As in this answer, you will need to
- process the output of
git diff --stat
in order to get the name of the folders
- check if
- that folder existed in the
<commit-hash-1>
and not in <commit-hash-2>
(meaning an ls-files for that path does not list any file)
- the reverse for a deleted folder
With Git 2.31 (Q1 2021), "git {diff,log} --{skip,rotate}-to=<path>
" allows the user to discard diff output for early paths or move them to the end of the output.
So you can order the folder order output, in order to process said output in the optimal expected way.
See commit 1eb4136 (11 Feb 2021) by Junio C Hamano (gitster
).
(Merged by Junio C Hamano -- gitster
-- in commit 845d603, 25 Feb 2021)
diff
: --{rotate,skip}-to=
In the implementation of "git difftool
"(man), there is a case where the user wants to start viewing the diffs at a specific path and continue on to the rest, optionally wrapping around to the beginning.
Since it is somewhat cumbersome to implement such a feature as a post-processing step of "git diff
"(man) output, let's support it internally with two new options.
- "
git diff --rotate-to=C
"(man), when the resulting patch would show paths A B C D E
without the option, would "rotate" the paths to shows patch to C D E A B
instead.
It is an error when there is no patch for C
is shown.
- "
git diff --skip-to=C
"(man) would instead skip the paths before C
, and shows patch to C D E
.
Again, it is an error when there is no patch for C
is shown.
- "
git log [-p]
"(man)" also accepts these two options, but it is not an error if there is no change to the specified path.
Instead, the set of output paths are rotated or skipped to the specified path or the first path that sorts after the specified path.
diff-options
now includes in its man page:
--skip-to=<file>
--rotate-to=<file>
Discard the files before the named from the output
(i.e. 'skip to'), or move them to the end of the output
(i.e. 'rotate to'). These were invented primarily for use
of the git difftool
command, and may not be very useful
otherwise.
gitdiffcore
now includes in its man page:
diffcore-rotate: For Changing At Which Path Output Starts
This transformation takes one pathname, and rotates the set of
filepairs so that the filepair for the given pathname comes first,
optionally discarding the paths that come before it. This is used
to implement the --skip-to
and the --rotate-to
options. It is
an error when the specified pathname is not in the set of filepairs,
but it is not useful to error out when used with "git log
" family of
commands, because it is unreasonable to expect that a given path
would be modified by each and every commit shown by the "git log"
command.
For this reason, when used with "git log
", the filepair
that sorts the same as, or the first one that sorts after, the given
pathname is where the output starts.
Use of this transformation combined with diffcore-order will produce
unexpected results, as the input to this transformation is likely
not sorted when diffcore-order is in effect.
And you can resume a diff too:
With Git 2.31 (Q1 2021), "git difftool
"(man) learned --skip-to=<path>
option to restart an interrupted session from an arbitrary path.
See commit 1c88102 (19 Feb 2021) by ZheNing Hu (adlternative
).
(Merged by Junio C Hamano -- gitster
-- in commit 6eea44c, 25 Feb 2021)
difftool.c
: learn a new way start at specified file
Signed-off-by: ZheNing Hu
git difftool
(man) only allow us to select file to view in turn.
If there is a commit with many files and we exit in the middle, we will have to traverse list again to get the file diff which we want to see.
Therefore,teach the command an option --skip-to=<path>
to allow the user to say that diffs for earlier paths are not interesting (because they were already seen in an earlier session) and start this session with the named path.
git difftool
now includes in its man page:
--rotate-to=<file>
Start showing the diff for the given path,
the paths before it will move to end and output.
--skip-to=<file>
Start showing the diff for the given path, skipping all
the paths before it.