Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

bash - How do I pass a range of commits to git log?

Ok I give up, I am a Bash noob.

This:

$ git log --no-walk --oneline 6980e6ecede8e188f434f6da669c2297f28decfe 458567536c1f20498da033cb0e42da74439ef12e

prints:

4585675 NNN bethDataFiles, allBethFiles belong to game/game/constants.py
6980e6e NNN bethDataFiles, allBethFiles belong to game/game/constants.py

This:

git log -g --pretty=format:'%ai %H' | awk '$0 >= "2016-04-13" && $0 <= "2016-04-15"'| cut -d' ' -f 4 | awk '!a[$0]++' | tr '
' ' '

prints me a range of commits:

ba4ee4b099d23642e6cad56d9f41974f6e767781 1daaede0f4e11cae0e0bb00b9ebb43bba4f5671 ...

Now why on earth piping this command to git log as in:

git log -g --pretty=format:'%ai %H' | awk '$0 >= "2016-04-13" && $0 <= "2016-04-15"'| cut -d' ' -f 4 | awk '!a[$0]++' | tr '
' ' ' | git log --format='%h %s %ai' --no-walk

only shows me the first commit:

ba4ee4b _load_active_plugins pre BAPI code - superseded by games.py API: 2016-04-14 19:38:41 +0200

?

$ git --version
git version 2.6.1.windows.1
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

git log does not read any input from stdin. Try doing echo "abcd123" | git log --no-walk and you will notice that git log will ignore stdin. It will look for a commit hash specified as an argument, but there is none. Hence, it will use the default HEAD, and print the latest commit on your current branch.

To print ranges of commit, you could for example do:

If you know the first and last commit hash:

git log abcd123..4567abc

If you know the time interval:

git log --since="10 days ago" --until="5 days ago"

Or if you know the specific dates:

git log --since="2016-04-13" --until="2016-04-15"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...