2

Lets assume I have a develop branch and I work in some feature branch, where I have one or more commits, I constantly amend commits as well as doing rebase of them with some other branches (to keep the commit history clean for future). At each stage I do diffs locally relative to the develop. So I have a set of diffs and I want to see the difference between them. How can I do that easily? What kind of git command sequence can I use?

Update

The solution is to have two diffs related to the develop. Have the copy of the repository in develop, apply first diff. Have anther copy and apply another patch. Use some comarison tool and compare two repositories. That would be the result that I expect. The problem with this approach is that I need to have at least two copies of the repository and use some tool to make a diff of directories. Another approach, which is probably better, is to use two branches, apply patches and commit changes, then compare branches. The question: is there something more simple in git commands to do that? Something like take this branch, and two diff files, return me diff?

user14416
  • 2,922
  • 5
  • 40
  • 67
  • 1
    Possible duplicate of [Is there a way to compare two diffs or patches?](http://stackoverflow.com/questions/8569699/is-there-a-way-to-compare-two-diffs-or-patches) – Maru Mar 16 '16 at 10:16
  • Hmm, there is no accepted answer there, and those answers do not answer my question as well. – user14416 Mar 16 '16 at 13:49
  • why not? In my opinion, both answers will just do what you ask for: compare two diffs. Please test and elaborate how the result is different from what you would expect. – Maru Mar 16 '16 at 14:06
  • I have tried to elaborate my question, the first answer is having diff of patch files, that is not what I want, the second answer uses git commits to compare, in my cases the diffs are not in git history (they was already amended and/or rebased) – user14416 Mar 16 '16 at 15:58

1 Answers1

5

Your second workflow is the answer. Here is a possible alias:

diffdiff = !git stash save -u -q &&
    git apply $1 && git add -A && git commit -q -m"1" &&
    git reset --hard HEAD@{1} -q &&
    git apply $2 && git add -A && git commit -q -m"2" &&
    git reset --hard HEAD@{1} -q && git stash pop -q &&
    git diff HEAD@{3} HEAD@{1} && :

Call it on the branch where you want to apply the diffs with diff files located outside of the repository.

git diffdiff <diff_file_1> <diff_file_2>

Not a multiplatform solution, tested on osx, with zsh and bash shells. If you are okay to do it manually it is quite a bit simpler, much of the complication here is to provide a kind-of-foolproof solution. Also the first line of output is noise, seems like git stash pop doesn't obey the --quiet parameter.

(Edit: There is no need for the temporary branch, so I simplified the alias.)

peterfoldi
  • 7,451
  • 5
  • 21
  • 19