I'm new to git and I'm trying to understand the difference between a squash and a rebase. As I understand it you perform a squash when doing a rebase.
相关问题
- Why does recursive submodule update from github fa
- Extended message for commit via Visual Studio Code
- Emacs shell: save commit message
- Can I organize Git submodules in a flat hierarchy?
- Upload file > 25 MB on Github
相关文章
- 请教Git如何克隆本地库?
- GitHub:Enterprise post-receive hook
- Git Clone Fails: Server Certificate Verification F
- SSIS solution on GIT?
- Is there a version control system abstraction for
- ssh: Could not resolve hostname git: Name or servi
- Cannot commit changes with gitextensions
- git: retry if http request failed
Merge commits: retains all of the commits in your branch and interleaves them with commits on the base branch
Merge Squash: retains the changes but omits the individual commits from history
Rebase: This moves the entire feature branch to begin on the tip of the master branch, effectively incorporating all of the new commits in master
More on here
Merge squash merges a tree (a sequence of commits) into a single commit. That is, it squashes all changes made in n commits into a single commit.
Rebasing is re-basing, that is, choosing a new base (parent commit) for a tree. Maybe the mercurial term for this is more clear: they call it transplant because it's just that: picking a new ground (parent commit, root) for a tree.
When doing an interactive rebase, you're given the option to either squash, pick, edit or skip the commits you are going to rebase.
Hope that was clear!
Both
git merge --squash
andgit rebase --interactive
can produce a "squashed" commit.But they serve different purposes.
git merge --squash abranch
will produce a squashed commit on the destination branch, without marking any merge relationship.
(Note: it does not produce a commit right away: you need an additional
git commit -m "squash branch"
)This is useful if you want to throw away the source branch completely, going from (schema taken from SO question):
to:
and then deleting
tmp
branch.git rebase --interactive
replays some or all of your commits on a new base, allowing you to squash (or more recently "fix up", see this SO question), going directly to:
If you choose to squash all commits of
tmp
(but, contrary tomerge --squash
, you can choose to replay some, and squashing others).So the differences are:
merge
does not touch your source branch (tmp
here) and creates a single commit where you want.rebase
allows you to go on on the same source branch (stilltmp
) with: