Though the merge form seems simpler for now, the reason for the pull form will become apparent when discussing multiple developers. Note an important difference: no new commit object is created for the merge. Let the current head be called current, and the head to be merged called merge. The must be one of the following: --soft Does not touch the index file nor the working tree at all but resets the head to , just like all modes do. The first, as explained above, is to draw the changes from a new feature branch into the main branch.
This keeps the feature branch up to date with the latest bug fixes and new features added to the main branch. Now you want to bring in those changes you made to the headers. One disadvantage of doing the above is that your feature branch will end up with a lot of merge commits. Git has no way of telling which change should take precedence. These commands perform the following operations.
This is the default action. Any changes to tracked files in the working tree since are discarded. . If a file that is different between and the index has unstaged changes, reset is aborted. The second use pattern is to draw the main branch into a feature branch you are developing.
So make sure to commit whatever changes you have made so far before you merge. Because B is the common ancestor between D and E , the files in F should contain the changes between B and D , namely the heading fixes, incorporated into the files from E. So, to complete the above example, say you check out the master head again and finish writing up the new data for your paper. Git only shifts the head pointers around. Important note: Git can get very confused if there are uncommitted changes in the files when you ask it to perform a merge. To resolve the commit, edit the files to fix the conflicting changes. Doing this regularly reduces the risk of creating a conflict when you merge your feature into the main branch.
In this case, all Git needs to do is set current to point to E. Then run git add to add the resolved files, and run git commit to commit the repaired merge. An alternative that solves this problem is , although that comes with problems of its own. You can do so with the git merge or git pull command. If the ancestor-commit equals merge, then do nothing.
Git remembers that you were in the middle of a merge, so it sets the parents of the commit correctly. Common Merge Use Patterns There are two common reasons to merge two branches. In other words, --merge does something like a git read-tree -u -m , but carries forward unmerged index entries. Resolving Conflicts A conflict arises if the commit to be merged in has a change in one place, and the current commit has a change in the same place. Head B gets updated; nothing is done to head A. If ancestor-commit equals current, then do a fast forward merge.
. . . . .
. . . . .
. . . . . . .
. . . . . .