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)
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.
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.
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.
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).
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.
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
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