Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git merge without auto commit

Tags:

git

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.

like image 725
selbie Avatar asked Dec 27 '11 03:12

selbie


People also ask

Can I merge without commit?

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.

How do I manually merge in git?

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.

How do I stop git from auto merging?

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 .

What is a non merge commit?

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.


1 Answers

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 
like image 71
manojlds Avatar answered Sep 16 '22 16:09

manojlds