Why don't I have to commit after git merge

11,077

Solution 1

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.

Solution 2

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

Solution 3

The merged files, which don't have conflicts are already merged. You can directly push your merged files.

Share:
11,077

Related videos on Youtube

techsjs2013
Author by

techsjs2013

Updated on September 15, 2022

Comments

  • techsjs2013
    techsjs2013 over 1 year

    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)