1

Do you know how can I see the differences between multiple non-consecutive commits and the current commit ? Let's say I have a user story '457', and here are all changes I made while implementing it:

$ git log1 | grep '457'
* 3451c32 - (2 days ago) 457: Sql for converting from kJ/g to kJ/100g 
* 51ebc26 - (3 days ago) 457: Refactoring code
* 4e0c3de - (3 days ago) 457: Refact constructDataForGrid 
* 50fcef2 - (8 days ago) 457: Dont show value while empty or zero 
* a901da1 - (8 days ago) 457: Dynamic conversion done 
* 6adf6e4 - (8 days ago) 457: Refactor constant: DBTechnicalDataID and UITechnicalDataID 
* bb961eb - (8 days ago) 457: Show total unit on create 
* fea5bb6 - (9 days ago) 457: Add comment for TabDataTag.java

How can I do something like git diff 457 HEAD, where 457 contains all my above changes ?

FYI, the git log1 is taken from here: Pretty git branch graphs

Community
  • 1
  • 1
Hoa Nguyen
  • 13,452
  • 11
  • 45
  • 44
  • `git diff` compares one commit to another commit (it does have some additional abilities but this is its fundamental operation). Each commit is a complete, standalone entity: it has no "changes" until you compare it against another commit (which is of course what `git diff` does but if we go this way you're then saying "I want to compare my changes by comparing my changes", which gets us nowhere). `HEAD` is one specific commit. Pick some other specific commit, and you may compare that against HEAD (or HEAD against that). It's otherwise entirely opaque to me what you actually want to do. – torek Mar 18 '16 at 04:48
  • is `457` in it's own branch? or is it all sat on `master`/the same branch? – Harmelodic Mar 18 '16 at 10:51
  • 457 is not a branch, it is just a prefix I gave to each commit to said that they belong to the same User Story (i.e. 457 in this case) – Hoa Nguyen Mar 18 '16 at 10:54
  • @torek: Let's say that you have two commit (commit_1, commit_5, commit_10). And in the mean time, people also commit another (commit_2, commit_3....). I want to see the differences between only commit_1, 5, 10 and the version before it). I can do the same by git revert to make a new commit on top, then do git diff with the current. I wonder if there is a similar way to do it ? – Hoa Nguyen Mar 18 '16 at 10:59
  • If you want to compare `commit1` vs `commit5`, just `git diff` those two. If you want to see what you changed in `commit5` as compared to `commit4`, just diff *those* two (this is easily expressed as `git show commit5`). If you want to compare 5-vs-10, `git diff` those two again, but if you want to see what you did in 10, use `git show` on it, and so on. – torek Mar 18 '16 at 12:38
  • 1
    @torek: no, I want to see what I added in commit1, commit5, commit10, all of them at the same time. As I told you before, I can do the trick by using git revert on them, then make the git diff. But I think it is not a really beautiful approach. – Hoa Nguyen Mar 18 '16 at 13:27
  • 2
    Oh: you want to, in essence, turn commit1 into a patch, then turn commit5 into a patch, then turn commit10 into a patch; then add all these patches (with nothing in between them) to... something? To do that, get on a private branch (starting with whatever commit you want to add them to), then `git cherry-pick` them. – torek Mar 18 '16 at 20:09
  • 1
    Does this answer your question? [Get a cumulative git diffs for multiple non-consecutuve commits](https://stackoverflow.com/questions/38842588/get-a-cumulative-git-diffs-for-multiple-non-consecutuve-commits) – xhienne Feb 13 '21 at 19:17

1 Answers1

-2
git log --grep <story name/number>

for an example

git log --grep 457
DDS
  • 149
  • 1
  • 9
  • 1
    This is not what the OP asked for: it will *list* the commits of interest, not show a combined diff with all of those commits’ effects. – bdesham Oct 18 '18 at 22:01