Is it possible to do a git merge
, but without a commit?
"man git merge" says this:
With --no-commit perform the merge but pretend the merge failed and do not autocommit, to give the user a chance to inspect and further tweak the merge result before committing.
But when I try to use git merge
with the --no-commit
it still auto-commits. Here's what I did:
$> ~/git/testrepo$ git checkout master Switched to branch 'master' $> ~/git/testrepo$ git branch * master v1.0 $> ~/git/testrepo$ git merge --no-commit v1.0 Updating c0c9fd2..18fa02c Fast-forward file1 | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) $> ~/git/testrepo$ git status # On branch master # Your branch is ahead of 'origin/master' by 1 commit. # nothing to commit (working directory clean)
A subsequent git log
reveals all the commits from the v1.0 branch merged into master.
With --no-commit perform the merge and stop just before creating a merge commit, to give the user a chance to inspect and further tweak the merge result before committing. Note that fast-forward updates do not create a merge commit and therefore there is no way to stop those merges with --no-commit.
To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch. This example merges the jeff/feature1 branch into the main branch.
Restore the unwanted files then with git checkout -- filename . @marckassy: But you could then git reset HEAD and git add -p to select what you want. To shut off the initial merge completely, add -s ours .
A "non-merge" commit is a commit that introduces an actual code change. A merge commit just moves around changes that were already introduced by non-merge commits.
Note the output while doing the merge - it is saying Fast Forward
In such situations, you want to do:
git merge v1.0 --no-commit --no-ff
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With