Home > Software engineering >  How to show "<short commit hash> <changed files separated by ,>" for a given r
How to show "<short commit hash> <changed files separated by ,>" for a given r

Time:06-23

I need an output like this

adfaadf foo.txt
dfafdaf bar.txt,zar.txt
...

I have this command

git --no-pager log --name-only --oneline --format="%h" master..

But it puts a line like this

foo.txt
adfaadf

bar.txt,zar.txt
dfafdaf

If the file comes before or after the hash is not a big difference to my I just want them in the same line

CodePudding user response:

You have to roll this on your own, but the following should work:

git rev-list master.. | while read -r commit; do
  printf '%s %s\n' \
    "$commit" \
    "$(git --no-pager show --name-only --format= $commit | paste -sd,)";
done

Sample output of git.git:

0703251124a438805b6a7994af1c84280976414f 
4acffdb9414cbf57841cdd96a134bbf9beda2254 
e42bc4566fa2f00e95e2524742f4aba9e8dba3ba builtin/fetch.c
378b51993aa022c432b23b7f1bafd921b7c43835 Documentation/git-gc.txt
9bef0b1e6ec371e786c2fba3edcc06ad040a536c builtin/branch.c
b2463fc30a43a43b5de788fa1611603f84097873 builtin/fetch.c
763f9739486ebf52dadb6c56742daf07e738829f 
8834ffe0ab92dabda3fabd6fa2160ac02869765c setup.c
518afcbc48f4314bcfb72371410281e4d6e494fd Documentation/config/safe.txt,git-compat-util.h
a3ba4fa715c67329736c9483f4b3fdab99cee50f setup.c

Or, a version that better matches the output given in your question:

git rev-list master.. | while read -r commit; do
  git --no-pager show --name-only --format='%h' $commit | paste -sd ' \0,';
done

generates the following output for git.git:

0703251124 
4acffdb941 
e42bc4566f builtin/fetch.c
378b51993a Documentation/git-gc.txt
9bef0b1e6e builtin/branch.c
b2463fc30a builtin/fetch.c
763f973948 
8834ffe0ab setup.c
518afcbc48 Documentation/config/safe.txt,git-compat-util.h
a3ba4fa715 setup.c
  •  Tags:  
  • git
  • Related