When I encounter a merge conflict using git rebase
, how can I identify the source of the conflict in terms of commits, rather than just file difference
Many times you'll be in the middle of a rebase and want to skip those commits that aren't needed.
Unfortunately, while git status
tells you that you're in the middle of commit and recommends using git rebase --continue
git rebase --skip
or git rebase --abort
, it doesn't tell you what commit you're currently on.
So it can oftentimes be hard to know if you should git rebase --skip
or not.
However, there is still a way to find out which commit you're on by running:
git log -1 $(< .git/rebase-apply/original-commit)
This may be a new feature, but REBASE_HEAD
gives you the commit where you're currently stopped (e.g. if the commit failed to apply). If you want to see the commit in full you can use
git show REBASE_HEAD
As a more verbose alternative, you can use git rebase --show-commit-patch
. The docs say they are equivalent.
If you want to see what's changed between where you're rebasing from and where you're rebasing to, you can get a diff between the two branches. For example, if you're rebasing from master
onto origin/master
you can use:
git diff master..origin/master
Or if you want to see the changes as individual commits:
git log -p master..origin/master
If you'd prefer to use the hash or maybe are coming back to a rebase after a while and can't remember which branches you're rebasing, you can use git status
to see the two branches. For example:
You are currently rebasing branch 'master' on 'b5284275'
Then, to see what's changed you can use:
git diff master..b5284275