【GIT】如何列出2个branch/tag/commitId 之间的所有commit

复习git log的用法

Reference:git log 用法

语法

git log [<options>] [<revision-range>] [[--] <path>]

常用用法

git log foo bar ^baz # 表示 log/bar 中包含,但是baz中不包含的commit,`^` 在这里表示取反

# `..` 可以实现相同的含义
git log origin..HEAD # 和下面这句表示相同的含义, 表示列出HEAD独有的commit
git log HEAD ^origin

# `...` 可以filter掉二者共同的commit
git log A B --not $(git merge-base --all A B) # 表示A/B 中包含,但是他们最新的父节点不包含的commit
git log A...B # 表示列出A和B独有的commit

列出2个branch之间的所有commit

  • 有2个branch testBranch1testBranch2
git log testBranch1 testBranch2 #  testBranch1或testBranch2 包含的commit
git log ^testBranch1 testBranch2 # testBranch1不包含 testBranch2 包含的commit
git log testBranch1..testBranch2 # testBranch1不包含 testBranch2 包含的commit
git log testBranch1...testBranch2 # testBranch1或testBranch2独有的commit
  • 如果是远端(remote)的branch,加上origin
git log origin/testBranch1 origin/testBranch2 #  testBranch1或testBranch2 包含的commit
git log ^origin/testBranch1 origin/testBranch2 # testBranch1不包含 testBranch2 包含的commit
git log origin/testBranch1..origin/testBranch2 # testBranch1不包含 testBranch2 包含的commit
git log origin/testBranch1...origin/testBranch2 # testBranch1或testBranch2独有的commit

如果远端没有这个branch,会报错。

列出2个tag之间的所有commit

  • 有2个tag testTag1testTag2
git log testTag1 testTag2 
git log ^testTag1 testTag2 
git log testTag1..testTag2 
git log testTag1...testTag2 
  • 但对于tag貌似不能直接访问remote 的tag 要把tag 拉到local才可以

列出2个commitid 之间的commit

直接把前面的branch 或者tag 替换成commit id 的hash值即可

输出格式化

 git log --pretty='format:%an, %h, %cs, %s' branch1..branch2

输出的格式如下:

Author, commitId, 2023-09-27, commit msg

你可能感兴趣的:(shell,git)