1

I'm about to take over work on a git branch that was started by someone else on my team. He had to make quite a few changes, and I'm also going to have to make quite a few changes. This will all be happening while other devs are merging smaller changes to the target branch.

Before I start making my changes on this branch, I want to record in a diff file all the changes that were made in this branch. That is like HEAD vs. TAIL, but I don't know how to do that.

I've seen ways to compare head against the "first" commit, but that's not quite what I need. I believe also that comparing HEAD against the target branch wouldn't be right, because that would be HEAD of that branch, not the commit my branch was branched from.

David M. Karr
  • 14,317
  • 20
  • 94
  • 199
  • 1
    Try using `git mergebase your-branch original-branch`, then use the sha that is reported as your "older commit" when comparing. – Lasse V. Karlsen Oct 18 '18 at 15:52
  • `git diff HEAD `? – Matt Messersmith Oct 18 '18 at 16:07
  • I believe Lasse's answer is correct, but I'm examining the results closely. Diffing against the target branch would likely compare against the local HEAD of that branch, which is not what I want. – David M. Karr Oct 18 '18 at 16:09
  • Your question stands on its own without that addition, but I'm curious: What do you need that diff file for? – lucidbrot Oct 18 '18 at 18:13
  • Do you want to see what other devs did while you were working on your own, or do you want to see what you did disregarding any work done by others? – j6t Oct 19 '18 at 09:06
  • @lucidbrot The changes I will have to add to the branch will be significant, and will take a while. By the time we get to the point where we're ready to merge this back to the target branch, it may have diverged so much for a merge to be impractical. Saving the diff of the changes made so far might make it easier to make those changes again. – David M. Karr Oct 19 '18 at 15:46
  • @LasseVågsætherKarlsen if you add your comment as an answer, I'll mark it correct (or at least suffices for what I need). – David M. Karr Oct 19 '18 at 15:46
  • @DavidM.Karr I may be wrong, but couldn't you more easily deal with this by merging the target branch into your branch every now and again? that way, you can continuously deal with the merge conflicts and adapt to their changes – lucidbrot Oct 19 '18 at 15:50
  • Of course. I'm also doing that, but this set of changes requires changing almost every source file in the project, and this is the second time I've tried to get through this before too many other conflicting changes went in. Having a record of the changes required at each major step will be helpful if we have to do this again. – David M. Karr Oct 19 '18 at 22:54

1 Answers1

0

This is taken form https://stackoverflow.com/a/28193089/2793683, but you can simply put a tag on both change sets that you are wanting to compare and then use the following:

git diff tag1..tag2 > mypatch.patch
dmoore1181
  • 1,793
  • 1
  • 25
  • 57