![](/img/trans.png)
[英]How to tell the last commit of a given git branch merged into another branch to find changes made on the branch?
[英]Git merged branch's last commit/committer
可能已經有人問過了,但我在這里找不到。
我有一個分支FEATURE
合並到一個分支STABLE
,目前當我從STABLE
執行git show
,我得到了最后一次提交
commit 265d684b67e66ba762bd438c44e49881f7fd571b
Merge: 5285837 78d9687
Author: xxxxx
Date: Thu Sep 6 18:58:46 2012 -0400
Merge branch 'FEATURE' into STABLE
無法弄清楚在FEATURE
分支合並到STABLE
之前,如何找到誰最后提交了對FEATURE
分支的更改?
這需要向最后提交一些更改的提交者發送通知。
讓我知道是否需要任何進一步的信息以及任何幫助/建議將不勝感激?
不完全是您要查找的內容,但要打印出所有遠程分支及其最后一次提交的作者,我在 Bash 上使用了以下命令:
IFS=$'\n' && for branch in $(git branch --all | grep "remotes/origin" | sed "s/->.*$//" | sort); do echo "$(git log --format=format:"%an" ${branch//[[:space:]]/} | head -n 1) - ${branch//[[:space:]]/}"; done | sort && unset IFS
請務必先執行git fetch --all
以便將所有公共分支鏡像到本地存儲庫中。
對於舊版本的 Git(1.9.x 及更早版本),git branch 的輸出是不同的,它沒有在箭頭(“->”)后打印本地跟蹤分支。
IFS=$'\n' && for branch in $(git branch --all | grep "remotes/origin" | sort); do echo "$(git log --format=format:"%an" ${branch//[[:space:]]/} | head -n 1) - ${branch//[[:space:]]/}"; done | sort && unset IFS
在您的情況下,合並前的最后一次提交具有 78d9687 哈希值。 它是提交消息中的第二個。 所以如果你想知道它是誰嘗試的
$ git show 78d9687
您可以使用相對提交表示法來顯示提交。 在您的示例中,由於您將 FEATURE 合並到 STABLE 中,因此 STABLE 上的最后一次提交是HEAD^1
(第一個父代),而 FEATURE 上的最后一次提交是HEAD^2
(第二個父代)。
因此,要顯示 FEATURE 引入的最后更改,您可以使用:
git show HEAD^2
顯示之前的那個:
git show HEAD^2~1
等等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.