1

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:

  • how do I go about "modifying" a commit before merging it into my working copy?
  • in case I can do the above, will that affect the remote repository? (I have read that one should not rebase after a push, for example)
  • in case I cannot do the above, how do I fix the changes after merging them? (eg. manually, ...)

In short: can someone give an overview of actions that are typically performed between a "fetch" and a "merge" to review and edit changes?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
matpen
  • 281
  • 2
  • 15

1 Answers1

1

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?"

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • That is just perfect. The `git merge --no-ff --no-commit && git reset` combo has the effect of importing the changes into my working copy, ready to be edited. – matpen Mar 30 '15 at 07:33
  • However, this approach will make the local and remote repos diverge. I solved with `git pull --rebase`, more infos [here](http://stackoverflow.com/questions/2452226/master-branch-and-origin-master-have-diverged-how-to-undiverge-branches). – matpen Mar 30 '15 at 08:28
  • @matpen True. I had forgotten about my old answer. – VonC Mar 30 '15 at 08:37