When I use Git checkout master~X, I will get the Xth merged commit, what I really want is the Xth real commit (not merged commits only).
How can I do that?
Thanks.
When I use Git checkout master~X, I will get the Xth merged commit, what I really want is the Xth real commit (not merged commits only).
How can I do that?
Thanks.
Try something like the following:
git checkout $(git log --no-merges --skip=2 -1 --format='%H')
Change --skip=2
to the number of non-merge commits you want to skip over. If you want the first non-merge commit, use --skip=0
; the second non-merge commit, use --skip=1
; the third, use --skip=2
; etc.
You could set up an alias (using this answer as a guide):
git config alias.co-non-merge '!git_co_non_merge() { git checkout `git log --no-merges --skip=$(($1 - 1)) -1 --format="%H"` ; } ; git_co_non_merge'
Add --global
to make it a global configuration change. Then you could just use git co-non-merge X
.
Merge commits can be replaced with rebase. Check this article out. However it only has effect on future branches.