如何使 git diff 显示与 github 的 pull request diff 相同的结果?
How to make git diff show the same result as github's pull request diff?
合并分支后,GitHub 尝试拉取请求时不再显示差异,但 git diff
仍会显示差异。
例如:
- 我有分支D
- 在分支 H 上创建了修补程序
- 将 H 合并到 D
- 在 D 上创建了更多内容
现在 GitHub 从 H 到 D 的拉取请求显示没有差异,但 git diff H D 显示差异。
我想做的是创建一个命令行工具来查看哪些旧分支(可能有很多)没有代码差异需要开发。现在我必须去 GitHub,做一个 pull request 和 select 每个分支看看是否有区别。
您可能需要 "triple-dot" 语法:
git diff D...H
另见 What are the differences between double-dot ".." and triple-dot "..." in Git diff commit ranges?
What I am trying to do is to create a command-line tool to see which old branches (there can be a lot) don't have code differences to develop
.
总结:这些中的任何一个都可以测试你上面引用的愿望:
# ALL OF THESE APPROACHES BELOW **WILL HAVE BLANK OUTPUT**
# if H has no changes added since it was last forked
# off of D
# Look for **changed lines** on H since it was last forked off of D
git diff D...H
# Exact same thing as above, as this is what the 3-dot syntax does
# under the hood:
git diff $(git merge-base D H) H
# Exact same thing as above (using the 2-dot syntax)
git diff $(git merge-base D H)..H
# Look for **added commits** on H which don't exist on D
git log --oneline --no-merges H ^D
进一步解释git log
命令的这种风格:
git log --oneline --no-merges feature_branch ^develop
这以单行格式显示所有提交(不包括合并),在 feature_branch
上 但不是(如 ^
所示)在 develop
分支上。类似于 git diff
或 git difftool
,如果没有要显示的更改(在本例中为提交),则输出为空白。
参考文献:
这个答案:What are the differences between double-dot ".." and triple-dot "..." in Git diff commit ranges?
另一个答案:What are the differences between double-dot ".." and triple-dot "..." in Git diff commit ranges?
我自己对上面 git log H ^D
风格 cmd 的注释:
我有更多的例子 in my dotfiles project here。例如:
FIND ALL GIT COMMITS WHICH ARE ON ONE BRANCH BUT NOT ON ANOTHER!
[keywords: git commits on one branch but not another, git commits not on branch, git commits in one branch but not another]
git log --no-merges branch1 ^branch2 ^branch3
show all commits which are ONLY on branch1, but NOT on branch2 or branch3, omitting all merge commits since they aren't new changes! See: Using Git, show all commits that are in one branch, but not the other(s) <========== SUPER USEFUL TO SEE WHAT CHANGES A BRANCH CONTAINS ON IT! ============
This is VERY USEFUL to see, for instance, what are all of the feature commits we've added to a long-running release branch named "branch1", into which which we have periodically been merging the latest master. Now, we can see which commits are in any given branch but not in master! Ex:
git log --no-merges branch1 ^master
show all NON-merge commits in branch1 which are NOT in master!
git log --oneline --no-merges branch1 ^branch2 ^branch3
same as above, but show only one line per commit! <======= EXCELLENT! (& SIMPLEST) ========
git lg --no-merges branch1 ^branch2 ^branch3
same as above, but using the git lg
git alias instead, to show condensed (one-line) output with extra information! <======= BEST! (perhaps) ========
上面的git lg
来自这里:https://coderwall.com/p/euwpig/a-better-git-log。要将其“安装”为 git 别名,只需 运行:
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
超级有用!
合并分支后,GitHub 尝试拉取请求时不再显示差异,但 git diff
仍会显示差异。
例如:
- 我有分支D
- 在分支 H 上创建了修补程序
- 将 H 合并到 D
- 在 D 上创建了更多内容
现在 GitHub 从 H 到 D 的拉取请求显示没有差异,但 git diff H D 显示差异。
我想做的是创建一个命令行工具来查看哪些旧分支(可能有很多)没有代码差异需要开发。现在我必须去 GitHub,做一个 pull request 和 select 每个分支看看是否有区别。
您可能需要 "triple-dot" 语法:
git diff D...H
另见 What are the differences between double-dot ".." and triple-dot "..." in Git diff commit ranges?
What I am trying to do is to create a command-line tool to see which old branches (there can be a lot) don't have code differences to
develop
.
总结:这些中的任何一个都可以测试你上面引用的愿望:
# ALL OF THESE APPROACHES BELOW **WILL HAVE BLANK OUTPUT**
# if H has no changes added since it was last forked
# off of D
# Look for **changed lines** on H since it was last forked off of D
git diff D...H
# Exact same thing as above, as this is what the 3-dot syntax does
# under the hood:
git diff $(git merge-base D H) H
# Exact same thing as above (using the 2-dot syntax)
git diff $(git merge-base D H)..H
# Look for **added commits** on H which don't exist on D
git log --oneline --no-merges H ^D
进一步解释git log
命令的这种风格:
git log --oneline --no-merges feature_branch ^develop
这以单行格式显示所有提交(不包括合并),在 feature_branch
上 但不是(如 ^
所示)在 develop
分支上。类似于 git diff
或 git difftool
,如果没有要显示的更改(在本例中为提交),则输出为空白。
参考文献:
这个答案:What are the differences between double-dot ".." and triple-dot "..." in Git diff commit ranges?
另一个答案:What are the differences between double-dot ".." and triple-dot "..." in Git diff commit ranges?
我自己对上面
git log H ^D
风格 cmd 的注释: 我有更多的例子 in my dotfiles project here。例如:FIND ALL GIT COMMITS WHICH ARE ON ONE BRANCH BUT NOT ON ANOTHER!
[keywords: git commits on one branch but not another, git commits not on branch, git commits in one branch but not another]git log --no-merges branch1 ^branch2 ^branch3
show all commits which are ONLY on branch1, but NOT on branch2 or branch3, omitting all merge commits since they aren't new changes! See: Using Git, show all commits that are in one branch, but not the other(s) <========== SUPER USEFUL TO SEE WHAT CHANGES A BRANCH CONTAINS ON IT! ============ This is VERY USEFUL to see, for instance, what are all of the feature commits we've added to a long-running release branch named "branch1", into which which we have periodically been merging the latest master. Now, we can see which commits are in any given branch but not in master! Ex:git log --no-merges branch1 ^master
show all NON-merge commits in branch1 which are NOT in master!git log --oneline --no-merges branch1 ^branch2 ^branch3
same as above, but show only one line per commit! <======= EXCELLENT! (& SIMPLEST) ========git lg --no-merges branch1 ^branch2 ^branch3
same as above, but using thegit lg
git alias instead, to show condensed (one-line) output with extra information! <======= BEST! (perhaps) ========
git lg
来自这里:https://coderwall.com/p/euwpig/a-better-git-log。要将其“安装”为 git 别名,只需 运行:git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
超级有用!