Generate git diff from commits list

Given a range of commits like

b9dc80c commit msg 1 #530 88a4d3c another commit 1010bce commit msg 2 #530 040ac6d commit msg 3 #530 6b72683 another commit ed17416 another commit f49bbbd commit msg 4 #530 

I would like to see diff of all changes in commits using #530 . So far, I have all the relevant hashes in a convenient format.

 git log --oneline | grep #530 | awk -F" " '{print $1}' | xargs echo # b9dc80c 1010bce 040ac6d f49bbbd 

Can I somehow merge these commits into one diff? That is, combine in memory without actually affecting the original repository. I know that I can cherry pick these commits in a separate branch and differentiate it, but it's too complicated.

The use case is that I want to see all the changes with the specified ticket identifier.

Example:

 echo a > file git add file && git commit "first" echo b > file git add file && git commit "second #XX" echo a > file git add file && git commit "third #XX" the-special-command 

with the "diff" I meant, the "comparison" #XX commits should give empty output instead of two separate changes to file .

+4
source share
3 answers

There are two options:

  • Script dance of union-comm-to-tempor-branch.
  • Use the combinediff command from patchutils .

Edit: you can simplify "log | grep" with log --grep and request it only for hashes with --format .

+1
source

Does git show print for all the sha-1 commands you found to do the trick for you ?:

git log --oneline | grep #530 | awk -F" " '{print $1}' | xargs git show --oneline

If you want to "merge" the output, you will only need to extract the unnecessary commit metadata ...

or something more "merging friendly": git log --oneline | grep a | awk -F" " '{print $1}' | xargs git show --pretty=format: git log --oneline | grep a | awk -F" " '{print $1}' | xargs git show --pretty=format:

0
source

Here's a slightly different approach:

 git checkout -b tempbranch b9dc80c git rebase -i f49bbbd^ # remove all the commits that you don't want from the editor, and # replace all the other "pick" commands except the first with "squash" git log -1 -p 

This creates a new branch, initially containing the same sequence of commits as the current branch. Then, on this branch, rebase will eliminate the commits you donโ€™t want, and squash the rest together in one message. Then step git log -1 -p show you the resulting patch (you can also use git diff HEAD^ HEAD or several other alternatives that give you a slightly different way out, depending on what you want to use the patch for). Note that depending on the nature of the changes in each commit, you may need to resolve some conflicts during rebase , but this is not necessarily abnormal ...

After that, you can undo the temporary branch:

 git checkout otherbranch git branch -D tempbranch 
0
source

Source: https://habr.com/ru/post/1499379/


All Articles