I have read that git pull
= git fetch
+ git merge
, and that the latter is usually preferred because it allows one to review changes before merging them.
Our small development team is sharing a git repo on a server. My colleague just pushed and I fetched, so that his commits are now in my local repository. I can see them with:
git log ..origin/mybranch
and inspect them with:
git diff <hash>
Now let's imagine that I want to merge the changes into my working copy, but I don't like some commits or parts of one commit.
My question is:
In short: can someone give an overview of actions that are typically performed between a "fetch" and a "merge" to review and edit changes?
You could do a merge without committing the result:
git merge --no-ff --no-commit <hash>
Then you reset the index (but not the working tree which reflects the merge)
git reset
Finally you can git add
any file or even git add --patch
part of files you want to keep in the result of that merge.
Or you can reject a merged file entirely: git checkout HEAD -- aFile
.
You have other options in "How do you merge selective files with git merge
?"