Search code examples
gitgit-branchgit-rebasegit-squash

Find the starting point to do a rebase -i


I am working in a branch (fork of master of course) and I have a series of commits.
I am interested in finding out exactly which commit is the one that is is where the branch started and is part of the master.

Why do I need this?
I want to squash all the commits with interactive rebase and I was wondering if there is an easy way to figure out what to pass to rebase command instead of manually counting commits to pass HEAD~52


Solution

  • git merge-base accepts two commits (which, as usual can be commit-hashes, branches, tags, etc) and returns the common ancestor they both diverged from.

    E.g.:

    mureinik@comupter ~/src/git/myproject [master] $ git merge-base master feature-1
    7c2232a4dd6c54ee8cc3f693ab8a0020ad82410b