-2

Which terminal command can i use to check which files were changed after a fast forward merge WHITHOUT the squash option ?
I need it for a CI so i can't execute one command and check by myself for a specific commit SHA and use it after to check the changes.

Lets take an example:

I create develop branch from master, i make my changes (5 commits) and i merge develop into master without squash option. At this point i want to execute a command that return me all changed files (comparing before and after the merge)

I can't use a specific commit hash in my command since it's for my CI and I don't know in advance what the hash will be

I've tried :

  • git diff --name-only HEAD~ but it compare the HEAD with the precedent commit and in case of fast forward without squash it will not necessarily be the commit before the merge.
  • git diff --name-only HEAD@{1} as @eftshift0 suggest but it is not working in CI
Mickael Rahmine
  • 372
  • 1
  • 7
  • 3
    Does this answer your question? [How to "git show" the diffs for a merge commit?](https://stackoverflow.com/questions/40986518/how-to-git-show-the-diffs-for-a-merge-commit) – TonyArra Feb 09 '23 at 17:30
  • In order for this to be possible, from the log alone, you need to make sure you have a merge commit. In the simple scenario you described, if `develop` was merged into `master` with fast-forward, you *can't* determine what changed on `master` from its history alone. If you use `--no-ff` to force a merge commit then you can diff `master` with it's first parent like in [eftshift0's answer](https://stackoverflow.com/a/75402019/184546). – TTT Feb 09 '23 at 17:35
  • What's the hard part? At the very least show us the command you did use and explain what's wrong with the result. – matt Feb 09 '23 at 21:45

1 Answers1

2

I guess you can use:

git diff --name-only HEAD~

Assuming you did not go anywhere after the merge (and that the merge is finished).

In cases when there is a fast-forward, you can do this right after merging:

git diff --name-status HEAD@{1}

That should work for non-ff scenarios too but it's a little flaky overall (if you move around after merging, the reference would point to a different commit).

eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • I think it would help to mention that there should be a merge commit. (I commented on the question about this.) – TTT Feb 09 '23 at 17:38
  • Great point. Let me add a tip in my answer (cause it's possible to do it with ff) – eftshift0 Feb 09 '23 at 21:37
  • "That should work for non-ff scenarios" Nonsensical. Delete "non"? – matt Feb 09 '23 at 21:46
  • Oh... now I'm wondering if I misunderstood the question. Regarding OP's statement, "I need it for a CI so i can't execute one command and check by myself", I was under the impression that the thing doing the merge isn't necessarily the same thing doing this check. I think the reflog would only work if the "thing" running the script, just did the merge? – TTT Feb 09 '23 at 21:53
  • @matt should I add a _too_ at the end? _That should work for non-ff scenarios **too**_ (which is what I meant... it works for both ff and non-ff). – eftshift0 Feb 10 '23 at 06:45
  • Aha! Yes, now I see – matt Feb 10 '23 at 09:30
  • thanks @eftshift0 `git diff --name-status HEAD@{1}` is working localy but not in CI. I suppose that HEAD@{1] refer to the previous HEAD and since in CI we have a new git environment it doesn't have access to it. – Mickael Rahmine Feb 13 '23 at 15:06
  • That will work wherever you are doing the merge.... if you want to run it in a place that is _not_ where the merge is taking place, then that won't work. – eftshift0 Feb 13 '23 at 15:13