Show current git operation interactive reboot

When in the middle of an interactive redirect, for example, git rebase -i HEAD~12 and adding / editing some commits, I am often confused as to which commit I am editing, especially when a merge conflict occurs:

 > git status rebase in progress; onto 55d9292 You are currently rebasing branch 'master' on '55d9292'. (fix conflicts and then run "git rebase --continue") (use "git rebase --skip" to skip this patch) (use "git rebase --abort" to check out the original branch) Unmerged paths: (use "git reset HEAD <file>..." to unstage) (use "git add <file>..." to mark resolution) both modified: file no changes added to commit (use "git add" and/or "git commit -a") 

How can I get a clear view of all corrections related to the current state? For example, what is a base patch, what patch am I collecting that corrects merge conflicts?

+2
git
source share
2 answers

If you have a conflict, you can run git show to see the latest commit being applied.

Then, when you open the conflict file, the conflict shows in one hand the state of the file at the last commit applied, and on the other hand, the state of the file in the currently applied commit.

Example:

I created a repo with the file "a". My first commit was to create a file:

 John@debian-John: ~/tmp/test (master #) βœ– (1) > touch a John@debian-John: ~/tmp/test (master #) βœ” > git add a John@debian-John: ~/tmp/test (master +) βœ” > git commit -m initial [master (root-commit) 298299e] initial 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 a 

Then I changed the file and committed it as "commit1":

 John@debian-John: ~/tmp/test (master) βœ” > echo aaa >a John@debian-John: ~/tmp/test (master *) βœ” > git add a John@debian-John: ~/tmp/test (master +) βœ” > git commit -m commit1 [master 90b49f8] commit1 1 file changed, 1 insertion(+) 

Then do it again to commit "commit2":

 John@debian-John: ~/tmp/test (master) βœ” > echo bbb >>a John@debian-John: ~/tmp/test (master *) βœ” > git add a John@debian-John: ~/tmp/test (master +) βœ” > git commit -m commit2 [master 14d798e] commit2 1 file changed, 1 insertion(+) 

Then I reinstalled commit1 to remove:

 John@debian-John: ~/tmp/test (master) βœ” > git rebase -i HEAD^^ Auto-merging a CONFLICT (content): Merge conflict in a error: could not apply 14d798e... commit2 When you have resolved this problem, run "git rebase --continue". If you prefer to skip this patch, run "git rebase --skip" instead. To check out the original branch and stop rebasing, run "git rebase --abort". Recorded preimage for 'a' Could not apply 14d798e... commit2 

Commit2 cannot be applied because its context has been changed (commit1 is missing). Note the error: could not apply 14d798e... commit2 , which has a commit2 hash. Although in conflict, if I run git show , I get:

 John@debian-John: ~/tmp/test (master *+|REBASE-i 1/1) βœ– (1) > git show commit 298299e3fb4e75c50aaa346c9f57c3b8885726f7 (HEAD) Author: John Doe <john@doe> Date: Fri Jul 21 15:59:01 2017 +0100 initial diff --git a/ab/a new file mode 100644 index 0000000..e69de29 John@debian-John: ~/tmp/test (master *+|REBASE-i 1/1) βœ” > git status interactive rebase in progress; onto 298299e Last command done (1 command done): pick 14d798e commit2 No commands remaining. You are currently rebasing branch 'master' on '298299e'. (fix conflicts and then run "git rebase --continue") (use "git rebase --skip" to skip this patch) (use "git rebase --abort" to check out the original branch) Unmerged paths: (use "git reset HEAD <file>..." to unstage) (use "git add <file>..." to mark resolution) both modified: a no changes added to commit (use "git add" and/or "git commit -a") 

And the content of a is:

 John@debian-John: ~/tmp/test (master +|REBASE-i 1/1) βœ” > cat a <<<<<<< HEAD ======= aaa bbb >>>>>>> 14d798e... commit2 

If HEAD is the last commit applied (initial), and the second part is a commit that has not been applied.

Hope this helps.

+1
source share

When in the middle of interactive forwarding, for example, git rebase -i HEAD~12 and adding / editing some commits, I am often confused as to which commit I am editing

With Git 2.17 (Q2 2018), the new option --show-current-patch gives the end user the option to use diff when git rebase (and git am ) stops with a conflict.

See commit fbd7a23 , commit 6633529 , commit 984913a (February 11, 2018) Nguyα»…n ThΓ‘i Ngọc Duy ( pclouds ) .
Assistant: Tim Landscheidt ( scfc ) .
(merger of Junio ​​C Hamano - gitster - commit 9ca488c , March 6, 2018)

rebase: enter and use pseudo-ref REBASE_HEAD

The new git rebase --show-current-patch is useful for viewing the commit associated with the current forwarding state.
Some, however, may find that the git show command behind it is too restrictive.
You can increase the context lines by doing a diff that ignores spaces ...

In these advanced use cases, the user can execute any command they want with the new pseudo ref REBASE_HEAD .

It also helps show where the commit stopped, which is hard to see from the previous patch that implements --show-current-patch .

0
source share

All Articles