From bc11bac3291c4cbeb4fb475c4fdc6fe3b22ba12e Mon Sep 17 00:00:00 2001 From: Philippe Blain Date: Mon, 22 May 2023 19:28:56 +0000 Subject: [PATCH 1/6] revisions.txt: use description list for special refs The special refs listed in 'gitrevisions' (under the '' entry) are on separate lines in the Asciidoc source, but end up as a single continuous paragraph in the rendered documentation (see e.g. [1]). In following commits we will mention additional special refs, so to improve legibility, use a description list such that every entry appears on its own line. Since we are already in a description list, use ':::' as the term delimiter. In order for the new description list to be aligned with the description under the '' entry, instead of being aligned with the last entry of the "in the following rules" nested list, use the "ancestor list continuation" syntax [2], i.e., leave an empty line before the continuation '+'. Do the same for the paragraph following the new description list ("Note that any..."). While at it, also use a continuation '+' before the "in the following rules" list, for correctness. The parser seems not to care here, but it's best to keep the sources correct. [1] https://git-scm.com/docs/gitrevisions#Documentation/gitrevisions.txt-emltrefnamegtemegemmasterememheadsmasterememrefsheadsmasterem [2] https://docs.asciidoctor.org/asciidoc/latest/lists/continuation/#ancestor-list-continuation Suggested-by: Victoria Dye Based-on-patch-by: Taylor Blau Signed-off-by: Philippe Blain Signed-off-by: Junio C Hamano --- Documentation/revisions.txt | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt index 9aa58052bc..ab5b8cf880 100644 --- a/Documentation/revisions.txt +++ b/Documentation/revisions.txt @@ -30,7 +30,7 @@ characters and to avoid word splitting. explicitly say 'heads/master' to tell Git which one you mean. When ambiguous, a '' is disambiguated by taking the first match in the following rules: - ++ . If '$GIT_DIR/' exists, that is what you mean (this is usually useful only for `HEAD`, `FETCH_HEAD`, `ORIG_HEAD`, `MERGE_HEAD` and `CHERRY_PICK_HEAD`); @@ -44,19 +44,25 @@ characters and to avoid word splitting. . otherwise, 'refs/remotes/' if it exists; . otherwise, 'refs/remotes//HEAD' if it exists. + + -`HEAD` names the commit on which you based the changes in the working tree. -`FETCH_HEAD` records the branch which you fetched from a remote repository -with your last `git fetch` invocation. -`ORIG_HEAD` is created by commands that move your `HEAD` in a drastic -way (`git am`, `git merge`, `git rebase`, `git reset`), -to record the position of the `HEAD` before their operation, so that -you can easily change the tip of the branch back to the state before you ran -them. -`MERGE_HEAD` records the commit(s) which you are merging into your branch -when you run `git merge`. -`CHERRY_PICK_HEAD` records the commit which you are cherry-picking -when you run `git cherry-pick`. + `HEAD`::: + names the commit on which you based the changes in the working tree. + `FETCH_HEAD`::: + records the branch which you fetched from a remote repository with + your last `git fetch` invocation. + `ORIG_HEAD`::: + is created by commands that move your `HEAD` in a drastic way (`git + am`, `git merge`, `git rebase`, `git reset`), to record the position + of the `HEAD` before their operation, so that you can easily change + the tip of the branch back to the state before you ran them. + `MERGE_HEAD`::: + records the commit(s) which you are merging into your branch when you + run `git merge`. + `CHERRY_PICK_HEAD`::: + records the commit which you are cherry-picking when you run `git + cherry-pick`. + + Note that any of the 'refs/*' cases above may come either from the `$GIT_DIR/refs` directory or from the `$GIT_DIR/packed-refs` file. From 6ec5f46071f793dbfa0915212b5708e2ce017053 Mon Sep 17 00:00:00 2001 From: Philippe Blain Date: Mon, 22 May 2023 19:28:57 +0000 Subject: [PATCH 2/6] revisions.txt: document more special refs Some special refs, namely HEAD, FETCH_HEAD, ORIG_HEAD, MERGE_HEAD and CHERRY_PICK_HEAD, are mentioned and described in 'gitrevisions', but some others, namely REBASE_HEAD, REVERT_HEAD, and BISECT_HEAD, are not. Add a small description of these special refs. Signed-off-by: Philippe Blain Signed-off-by: Junio C Hamano --- Documentation/revisions.txt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt index ab5b8cf880..b34f981622 100644 --- a/Documentation/revisions.txt +++ b/Documentation/revisions.txt @@ -32,8 +32,8 @@ characters and to avoid word splitting. first match in the following rules: + . If '$GIT_DIR/' exists, that is what you mean (this is usually - useful only for `HEAD`, `FETCH_HEAD`, `ORIG_HEAD`, `MERGE_HEAD` - and `CHERRY_PICK_HEAD`); + useful only for `HEAD`, `FETCH_HEAD`, `ORIG_HEAD`, `MERGE_HEAD`, + `REBASE_HEAD`, `REVERT_HEAD`, `CHERRY_PICK_HEAD` and `BISECT_HEAD`); . otherwise, 'refs/' if it exists; @@ -59,9 +59,18 @@ characters and to avoid word splitting. `MERGE_HEAD`::: records the commit(s) which you are merging into your branch when you run `git merge`. + `REBASE_HEAD`::: + during a rebase, records the commit at which the operation is + currently stopped, either because of conflicts or an `edit` command in + an interactive rebase. + `REVERT_HEAD`::: + records the commit which you are reverting when you run `git revert`. `CHERRY_PICK_HEAD`::: records the commit which you are cherry-picking when you run `git cherry-pick`. + `BISECT_HEAD`::: + records the current commit to be tested when you run `git bisect + --no-checkout`. + Note that any of the 'refs/*' cases above may come either from From 1ef3c61b7889e2aa76a8f0d32a88fbc09fca3b8e Mon Sep 17 00:00:00 2001 From: Philippe Blain Date: Mon, 22 May 2023 19:28:58 +0000 Subject: [PATCH 3/6] completion: complete REVERT_HEAD and BISECT_HEAD The pseudorefs REVERT_HEAD and BISECT_HEAD are not suggested by the __git_refs function. Add them there. Signed-off-by: Philippe Blain Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index dc95c34cc8..bcda376735 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -767,7 +767,7 @@ __git_refs () track="" ;; *) - for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD; do + for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD REVERT_HEAD BISECT_HEAD; do case "$i" in $match*|$umatch*) if [ -e "$dir/$i" ]; then From b7dd54a2c7df5e1dbe713807afb49fb77c9b7fc7 Mon Sep 17 00:00:00 2001 From: Philippe Blain Date: Mon, 22 May 2023 19:28:59 +0000 Subject: [PATCH 4/6] git-merge.txt: modernize word choice in "True merge" section The "True merge" section of the 'git merge' documentation mentions that in case of conflicts, the conflicted working tree files contain "the result of the "merge" program". This probably refers to RCS's 'merge' program, which is mentioned further down under "How conflicts are presented". Since it is not clear at that point of the document which program is referred to, and since most modern readers probably do not relate to RCS anyway, let's just write "the merge operation" instead. Signed-off-by: Philippe Blain Signed-off-by: Junio C Hamano --- Documentation/git-merge.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt index 0aeff572a5..23aefe2885 100644 --- a/Documentation/git-merge.txt +++ b/Documentation/git-merge.txt @@ -194,7 +194,7 @@ happens: versions: stage 1 stores the version from the common ancestor, stage 2 from `HEAD`, and stage 3 from `MERGE_HEAD` (you can inspect the stages with `git ls-files -u`). The working - tree files contain the result of the "merge" program; i.e. 3-way + tree files contain the result of the merge operation; i.e. 3-way merge results with familiar conflict markers `<<<` `===` `>>>`. 5. No other changes are made. In particular, the local modifications you had before you started merge will stay the From 4fa1edb98820ec6ddf52b004f9d616c34a8ddfd2 Mon Sep 17 00:00:00 2001 From: Philippe Blain Date: Mon, 22 May 2023 19:29:00 +0000 Subject: [PATCH 5/6] Documentation: document AUTO_MERGE Since 5291828df8 (merge-ort: write $GIT_DIR/AUTO_MERGE whenever we hit a conflict, 2021-03-20), when using the 'ort' merge strategy, the special ref AUTO_MERGE is written when a merge operation results in conflicts. This ref points to a tree recording the conflicted state of the working tree and is very useful during conflict resolution. However, this ref is not documented. Add some documentation for AUTO_MERGE in git-diff(1), git-merge(1), gitrevisions(7) and in the user manual. In git-diff(1), mention it at the end of the description section, when we mention that the command also accepts trees instead of commits, and also add an invocation to the "Various ways to check your working tree" example. In git-merge(1), add a step to the list of things that happen "when it is not obvious how to reconcile the changes", under the "True merge" section. Also mention AUTO_MERGE in the "How to resolve conflicts" section, when mentioning 'git diff'. In gitrevisions(7), add a mention of AUTO_MERGE along with the other special refs. In the user manual, add a paragraph describing AUTO_MERGE to the "Getting conflict-resolution help during a merge" section, and include an example of a 'git diff AUTO_MERGE' invocation for the example conflict used in that section. Note that for uniformity we do not use backticks around AUTO_MERGE here since the rest of the document does not typeset special refs differently. Closes: https://github.com/gitgitgadget/git/issues/1471 Signed-off-by: Philippe Blain Signed-off-by: Junio C Hamano --- Documentation/git-diff.txt | 9 ++++++++- Documentation/git-merge.txt | 9 +++++++-- Documentation/revisions.txt | 7 ++++++- Documentation/user-manual.txt | 27 +++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt index 52b679256c..08087ffad5 100644 --- a/Documentation/git-diff.txt +++ b/Documentation/git-diff.txt @@ -102,7 +102,11 @@ If --merge-base is given, use the merge base of the two commits for the Just in case you are doing something exotic, it should be noted that all of the in the above description, except in the `--merge-base` case and in the last two forms that use `..` -notations, can be any . +notations, can be any . A tree of interest is the one pointed to +by the special ref `AUTO_MERGE`, which is written by the 'ort' merge +strategy upon hitting merge conflicts (see linkgit:git-merge[1]). +Comparing the working tree with `AUTO_MERGE` shows changes you've made +so far to resolve textual conflicts (see the examples below). For a more complete list of ways to spell , see "SPECIFYING REVISIONS" section in linkgit:gitrevisions[7]. @@ -152,6 +156,7 @@ Various ways to check your working tree:: $ git diff <1> $ git diff --cached <2> $ git diff HEAD <3> +$ git diff AUTO_MERGE <4> ------------ + <1> Changes in the working tree not yet staged for the next commit. @@ -159,6 +164,8 @@ $ git diff HEAD <3> would be committing if you run `git commit` without `-a` option. <3> Changes in the working tree since your last commit; what you would be committing if you run `git commit -a` +<4> Changes in the working tree you've made to resolve textual + conflicts so far. Comparing with arbitrary commits:: + diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt index 23aefe2885..8625c5cb0e 100644 --- a/Documentation/git-merge.txt +++ b/Documentation/git-merge.txt @@ -196,7 +196,11 @@ happens: can inspect the stages with `git ls-files -u`). The working tree files contain the result of the merge operation; i.e. 3-way merge results with familiar conflict markers `<<<` `===` `>>>`. -5. No other changes are made. In particular, the local +5. A special ref `AUTO_MERGE` is written, pointing to a tree + corresponding to the current content of the working tree (including + conflict markers for textual conflicts). Note that this ref is only + written when the 'ort' merge strategy is used (the default). +6. No other changes are made. In particular, the local modifications you had before you started merge will stay the same and the index entries for them stay as they were, i.e. matching `HEAD`. @@ -336,7 +340,8 @@ You can work through the conflict with a number of tools: * Look at the diffs. `git diff` will show a three-way diff, highlighting changes from both the `HEAD` and `MERGE_HEAD` - versions. + versions. `git diff AUTO_MERGE` will show what changes you've + made so far to resolve textual conflicts. * Look at the diffs from each branch. `git log --merge -p ` will show diffs first for the `HEAD` version and then the diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt index b34f981622..6ea6c7cead 100644 --- a/Documentation/revisions.txt +++ b/Documentation/revisions.txt @@ -33,7 +33,8 @@ characters and to avoid word splitting. + . If '$GIT_DIR/' exists, that is what you mean (this is usually useful only for `HEAD`, `FETCH_HEAD`, `ORIG_HEAD`, `MERGE_HEAD`, - `REBASE_HEAD`, `REVERT_HEAD`, `CHERRY_PICK_HEAD` and `BISECT_HEAD`); + `REBASE_HEAD`, `REVERT_HEAD`, `CHERRY_PICK_HEAD`, `BISECT_HEAD` + and `AUTO_MERGE`); . otherwise, 'refs/' if it exists; @@ -71,6 +72,10 @@ characters and to avoid word splitting. `BISECT_HEAD`::: records the current commit to be tested when you run `git bisect --no-checkout`. + `AUTO_MERGE`::: + records a tree object corresponding to the state the + 'ort' merge strategy wrote to the working tree when a merge operation + resulted in conflicts. + Note that any of the 'refs/*' cases above may come either from diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index dc9c6a663a..aa385137ad 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -1343,6 +1343,33 @@ $ git diff -3 file.txt # diff against stage 3 $ git diff --theirs file.txt # same as the above. ------------------------------------------------- +When using the 'ort' merge strategy (the default), before updating the working +tree with the result of the merge, Git writes a special ref named AUTO_MERGE +reflecting the state of the tree it is about to write. Conflicted paths with +textual conflicts that could not be automatically merged are written to this +tree with conflict markers, just as in the working tree. AUTO_MERGE can thus be +used with linkgit:git-diff[1] to show the changes you've made so far to resolve +conflicts. Using the same example as above, after resolving the conflict we +get: + +------------------------------------------------- +$ git diff AUTO_MERGE +diff --git a/file.txt b/file.txt +index cd10406..8bf5ae7 100644 +--- a/file.txt ++++ b/file.txt +@@ -1,5 +1 @@ +-<<<<<<< HEAD:file.txt +-Hello world +-======= +-Goodbye +->>>>>>> 77976da35a11db4580b80ae27e8d65caf5208086:file.txt ++Goodbye world +------------------------------------------------- + +Notice that the diff shows we deleted the conflict markers and both versions of +the content line, and wrote "Goodbye world" instead. + The linkgit:git-log[1] and linkgit:gitk[1] commands also provide special help for merges: From 982ff3a649221d9db79049e5823425f645b3228e Mon Sep 17 00:00:00 2001 From: Philippe Blain Date: Mon, 22 May 2023 19:29:01 +0000 Subject: [PATCH 6/6] completion: complete AUTO_MERGE The pseudoref AUTO_MERGE is documented since the previous commit. To make it easier to use, let __git_refs in the Bash completion code complete it. Signed-off-by: Philippe Blain Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index bcda376735..945d2543b0 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -767,7 +767,7 @@ __git_refs () track="" ;; *) - for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD REVERT_HEAD BISECT_HEAD; do + for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD REVERT_HEAD BISECT_HEAD AUTO_MERGE; do case "$i" in $match*|$umatch*) if [ -e "$dir/$i" ]; then