Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why don't I have to commit after git merge

Tags:

git

git-merge

I have a repo master and I do with file1.txt and file2.txt

git checkout -b fix1

I then change file1.txt

and I do a

git commit -a

then I do a

git checkout master

then I do a

git checkout -b fix2

I then change file2.txt

and I do a

git commit -a

then git checkout master then a

git merge fix1
git marge fix2 

but if I do a

 commit -a 

I get

# On branch master
nothing to commit (working directory clean)
like image 657
techsjs2013 Avatar asked Feb 12 '13 15:02

techsjs2013


People also ask

Do you need to commit after merge git?

If there were uncommitted worktree changes present when the merge started, git merge --abort will in some cases be unable to reconstruct these changes. It is therefore recommended to always commit or stash your changes before running git merge.

Does merging make a new commit?

Merging your branch into master is the most common way to do this. Git creates a new commit (M) that is referred to as a merge commit that results from combining the changes from your feature branch and master from the point where the two branches diverged.

Do I need to commit before merge?

That is why committing first is a good idea. If you don't do it in that order, it will either merge fine (if the files you changed were not involved in any other commits that are being merged), or nothing will happen, and git will tell you that your merge can't be done.

What happens to commits after merge?

After the merge, the working tree and the index and the HEAD (the new merge commit) are all synchronized. In other words, Git does not merely make a new commit; it also changes the state of your working tree (and the index).


2 Answers

git merge commits automatically. If you don't want to commit add the --no-commit argument:

  --commit, --no-commit
      Perform the merge and commit the result. This option can be used to override --no-commit.

      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.
like image 110
Some programmer dude Avatar answered Oct 07 '22 15:10

Some programmer dude


If the merge succeeds without conflict, git will automatically commit it (which you should be able to verify by simply checking git log).

The documentation notes (emphasis added):

... "git merge topic" will replay the changes made on the topic branch since it diverged from master (i.e., E) until its current commit (C) on top of master, and record the result in a new commit along with the names of the two parent commits and a log message from the user describing the changes

If you want to avoid this, use the --no-commit flag:

git merge --no-commit fix1
like image 33
eldarerathis Avatar answered Oct 07 '22 16:10

eldarerathis