简体   繁体   中英

Reference all commits between master branch-tip and HEAD in git

I currently am branched out of master (call it branchA). I have made a couple of commits to branchA and would now like to squash commits together on my branch prior to merging to master. Usually I do something like this in my branchA repo:

git rebase -i HEAD~n

I would get n by doing a git log and manually counting the commits from (not including) the master branch tip until (and including) the branch's HEAD . For now the count has been easy as the commits are few.

Is there a simple way to reference all commits on current branch after master branch-tip commit?

You could try:

git rebase -i $( git merge-base master HEAD )

You are fiding the point where master and your current branch diverged (or at least, one of the latest common ancestors) and using it as the parameter for rebase. That might work.

If what you want to know is how many revisions there are on your branch:

git log --pretty=%h $( git merge-base master HEAD ) | wc -l

As a side note, you could just as easily squash without doing rebase:

git reset --soft $( git merge-base master HEAD )
git commit -m "Squashed feature"

IMHO warning: I don't see why people would rather go to an editor, edit God knows how many lines when a couple of commands would do the trick. But.... anyway.

Is there a simple way to reference all commits on current branch after master branch-tip commit?

Yes, just do this:

git rebase -i master

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM