I do have the following alias, to show me the commit history of any given file:
file-history = log --follow --date-order --date=short -C
It works well, but never shows "merge commits", while the file can have been modified in a branch we did merge into main, for example.
The solution is to add the option -m, but then it shows many, many, many merge commits, for which most of them seem unrelated to the commit history of the file.
What is the right way to write such an alias to make it behave correctly (like in BitBucket, for this matter): showing all commits that did change a file, and only those?
EXTRA INFORMATION --
Using -m shows way too many commits; concretely:
(In red rectangles, what I should see... that's what BitBucket displays...)
(BTW, I don't understand why the commit da3c94a1 is duplicated.)
Using -c shows even much more commits (the first commit that should be reported being in the bottom of the page) and displays the diffs (what I don't want to see here):
Same results for --cc:
And --first-parent shows weird results (as I don't see at all the commits I'm interested in):
NEW EXTRA INFORMATION --
And, with --first-parent -m, no change:
ANSWER TO TOREK --
To make things simpler, I've created the following test repo:
master master
C--D I--J
/ \ / \
A--B G--H M--N master
\ / \ /
E--F K--L
br1 br2
where I did merge br1
and br2
onto master
.
I've created commits which only changed one file at a time.
Commits which changed file1 (only):
A
C
F
I
L
Commits which changed file2 (only):
B
D
E
H
J
K
N
Commits which changed both files:
G
(the merge ofbr1
ontomaster
)M
(the merge ofbr2
ontomaster
)
Let's begin with the tests:
$ git log --decorate --date=short
2021-11-05 d670be5 (HEAD -> master, origin/master, origin/HEAD) Commit N
2021-11-05 838f65c Merge branch 'br2' (Commit M)
2021-11-05 7ae0238 (br2) Commit L
2021-11-05 affed14 Commit K
2021-11-05 ecd490f Commit J
2021-11-05 ca2e68f Commit I
2021-11-05 45d8231 Commit H
2021-11-05 eb356b8 Merge branch 'br1'
2021-11-05 9aaa030 (br1) Commit F
2021-11-05 552a403 Commit E
2021-11-05 86a71ff Commit D
2021-11-05 611bef2 Commit C
2021-11-05 eceafb8 Commit B
2021-11-05 e137033 Initial commit
You know what? I was expecting to see this instead:
2021-11-05 d670be5 (HEAD -> master, origin/master, origin/HEAD) Commit N
2021-11-05 838f65c Merge branch 'br2' (Commit M)
2021-11-05 ecd490f Commit J
2021-11-05 ca2e68f Commit I
2021-11-05 45d8231 Commit H
2021-11-05 eb356b8 Merge branch 'br1'
2021-11-05 86a71ff Commit D
2021-11-05 611bef2 Commit C
2021-11-05 eceafb8 Commit B
2021-11-05 e137033 Initial commit
That is, I was expecting to see neither commits E
and F
from br1
nor K
and L
from br2
. So, it seems I don't undertand everything...
Now, let's look at the file history of file2.txt
... Both GitHub and BitBucket --
I've tested both of them -- show me the following commits (and only those) when
asked to display the history of the file:
B
D
E
G
H
J
K
M
N
This is 1 of the 2 results I would have expected -- the other one being the
same without commits E
and K
, as I could have thought they would be hidden (as
being part of branches, not committed on master
).
Now, let's play with some "file history" commands:
$ git log --follow --date-order --date=short -C file2.txt
2021-11-05 d670be5 (HEAD -> master, origin/master, origin/HEAD) Commit N
2021-11-05 affed14 Commit K
2021-11-05 ecd490f Commit J
2021-11-05 45d8231 Commit H
2021-11-05 552a403 Commit E
2021-11-05 86a71ff Commit D
2021-11-05 eceafb8 Commit B
$ git log --follow --date-order --date=short -C -m file2.txt
2021-11-05 d670be5 (HEAD -> master, origin/master, origin/HEAD) Commit N
2021-11-05 838f65c Merge branch 'br2' (Commit M)
2021-11-05 838f65c Merge branch 'br2' (Commit M)
2021-11-05 affed14 Commit K
2021-11-05 ecd490f Commit J
2021-11-05 45d8231 Commit H
2021-11-05 eb356b8 Merge branch 'br1'
2021-11-05 eb356b8 Merge branch 'br1'
2021-11-05 552a403 Commit E
2021-11-05 86a71ff Commit D
2021-11-05 eceafb8 Commit B
$ git log --follow --date-order --date=short -C -c -s file2.txt
2021-11-05 d670be5 (HEAD -> master, origin/master, origin/HEAD) Commit N
2021-11-05 838f65c Merge branch 'br2' (Commit M)
2021-11-05 affed14 Commit K
2021-11-05 ecd490f Commit J
2021-11-05 45d8231 Commit H
2021-11-05 eb356b8 Merge branch 'br1'
2021-11-05 552a403 Commit E
2021-11-05 86a71ff Commit D
2021-11-05 eceafb8 Commit B
$ git log --follow --date-order --date=short -C --cc -s file2.txt
2021-11-05 d670be5 (HEAD -> master, origin/master, origin/HEAD) Commit N
2021-11-05 838f65c Merge branch 'br2' (Commit M)
2021-11-05 affed14 Commit K
2021-11-05 ecd490f Commit J
2021-11-05 45d8231 Commit H
2021-11-05 eb356b8 Merge branch 'br1'
2021-11-05 552a403 Commit E
2021-11-05 86a71ff Commit D
2021-11-05 eceafb8 Commit B
$ git log --follow --date-order --date=short -C -m --first-parent file2.txt
2021-11-05 d670be5 (HEAD -> master, origin/master, origin/HEAD) Commit N
2021-11-05 838f65c Merge branch 'br2' (Commit M)
2021-11-05 ecd490f Commit J
2021-11-05 45d8231 Commit H
2021-11-05 eb356b8 Merge branch 'br1'
2021-11-05 86a71ff Commit D
2021-11-05 eceafb8 Commit B
$ git log --follow --date-order --date=short -C --cc --full-history -s file2.txt
2021-11-05 d670be5 (HEAD -> master, origin/master, origin/HEAD) Commit N
2021-11-05 838f65c Merge branch 'br2' (Commit M)
2021-11-05 affed14 Commit K
2021-11-05 ecd490f Commit J
2021-11-05 45d8231 Commit H
2021-11-05 eb356b8 Merge branch 'br1'
2021-11-05 552a403 Commit E
2021-11-05 86a71ff Commit D
2021-11-05 eceafb8 Commit B
Let's analyse the results, one by one:
$ git log --follow --date-order --date=short -C file2.txt
does not show the merge commits. Incomplete results. Failure, then.
$ git log --follow --date-order --date=short -C -m file2.txt
does show all commits where file2.txt
has been changed, but duplicates the merge
commits. Partial failure...
$ git log --follow --date-order --date=short -C -c -s file2.txt
and
$ git log --follow --date-order --date=short -C --cc -s file2.txt
both show the 9 commits (7 "normal" + 2 merge) where file2.txt
has been
changed. Same results as on BitBucket and GitHub.
$ git log --follow --date-order --date=short -C -m --first-parent file2.txt
shows all commits on master
where file2.txt
has been changed, and the merge
commits. Could be the other expected results I had, but not the same as
BitBucket and GitHub. Let's discard it, then.
$ git log --follow --date-order --date=short -C --cc --full-history -s file2.txt
also shows the 9 commits.
So, the commands that give the same (complete) results as the ones from GitHub and BitBucket are:
$ git log --follow --date-order --date=short -C -c -s file2.txt
$ git log --follow --date-order --date=short -C --cc -s file2.txt
$ git log --follow --date-order --date=short -C --cc --full-history -s file2.txt
Coming back to my request, which may have been badly expressed, it is the following: I do want to see all commits that did change some file, in order to display the other files also changed in the same commits, and doing so discover the list of files I do have to change for some specific functional request.
Based on my real-world example, it seems that BitBucket was correctly
identifying those commits, and that my file-history
alias(es) did not... either
showing not enough commits, too much commits, or even inappropriate ones...
Coming back to that real-world example, the following commands:
$ git log --follow --date-order --date=short -C -c -s 32-factures-creation.R | wc -l
$ git log --follow --date-order --date=short -C --cc -s 32-factures-creation.R | wc -l
$ git log --follow --date-order --date=short -C --cc --full-history -s 32-factures-creation.R | wc -l
all return me 440 lines:
2021-10-18 d5590007 Merge branch 'master' of https://bitbucket.org/.../...
2021-10-18 6ccde740 Merge branch 'master' of https://bitbucket.org/.../...
2021-10-06 9d532874 Merge branch 'indexation-RMMMG-09-2021' into release/21.10
2021-10-04 d982c3d8 Merge branch 'indexation-RMMMG-09-2021' into release/21.10
2021-10-04 0a65134f Merge branch 'indexation-RMMMG-09-2021' into release/21.10
2021-10-02 728897b9 Merge branch 'indexation-RMMMG-09-2021' into release/21.10
2021-09-30 0df507b9 Simplify SQL expression in 32-factures-creation.R
2021-09-30 16f94a10 Update format of prsAnneeMois
2021-09-29 f9a6cafb Update "Facturation à l'employeur"
2021-10-02 22ef1194 Merge branch 'feature/103-upgrade-...-logo' into release/21.10
2021-09-20 9a2244d3 (tag: xxx_21-10-20_23-01-50, tag: sh_21-10-20_22-56-11, tag: sh_21-10-20_22-54-54, tag: 2021.10.20_23.04_xxx) Merge branch 'master' of https://bitbucket.org/mc.../...
2021-09-20 9fa77b1e Merge branch 'new-new-augm-eff'
2021-07-02 b4538cce Merge branch 'new-augm-eff' into release/21.07
2021-07-02 20c72364 (tag: 2021.07.01) Merge branch 'master' of https://bitbucket.org/.../...
...
That's way more than what I see on BitBucket:
2021-09-30 0df507b9 Simplify SQL expression in 32-factures-creation.R
2021-09-30 16f94a10 Update format of prsAnneeMois
2021-09-29 f9a6cafb Update "Facturation à l'employeur"
...
So, above, I still see too many commits. Still puzzled...