我習慣於運行一個git的比較,這將使當地git的轉速喜歡比較:git diff日期?
git diff HEAD HEAD~110 -- some/file/path/file.ext
是否有可能使用的日期呢?如果是這樣,怎麼樣?我希望能夠在上述示例中插入代替「110」的日期,例如「2012年12月4日」。
我習慣於運行一個git的比較,這將使當地git的轉速喜歡比較:git diff日期?
git diff HEAD HEAD~110 -- some/file/path/file.ext
是否有可能使用的日期呢?如果是這樣,怎麼樣?我希望能夠在上述示例中插入代替「110」的日期,例如「2012年12月4日」。
git diff HEAD '[email protected]{3 weeks ago}' -- some/file/path/file.ext
嚴格來說,這並非三週前的修訂。相反,它的位置HEAD
是在現在的三週前。但它可能足夠接近你的目的 - 如果當前分支的HEAD
穩步前進,這將是非常準確的,這是大多數人傾向於做的。您可以使用分支名稱而不是HEAD
來提高準確性。
也可以使用日期/時間,而不是現在的偏移量,如[email protected]{1979-02-26 18:30:00}
。見git help rev-parse
。
結合Jonathan Stray's suggestion to use git-rev-list --before
在給定日期找到修訂和Show just the current branch in Git:
#!/bin/sh
if [ $# -eq 0 ] || [ "$1" = "--help" ]; then
cat <<EOF
Usage: $0 DATE FILE...
git diff on FILE... since the specified DATE on the current branch.
EOF
exit
fi
branch1=$(git rev-parse --abbrev-ref HEAD)
revision1=$(git rev-list -1 --before="$1" "$branch1")
shift
revision2=HEAD
git diff "$revision1" "$revision2" -- "[email protected]"
調用此腳本日期和任選的一些文件名,例如
git-diff-since yesterday
git-diff-since '4 Dec 2012' some/file/path/file.ext
你想要的就是這個。
git diff HEAD '@{3 weeks ago}' -- some/file/path/file.ext
你應該@{3 weeks ago}
,不[email protected]{3 weeks ago}
比較。
有什麼區別?
如果你3周前在另一個分支上,[email protected]{3 weeks ago}
會指向分支的HEAD,另一方面@{3 weeks ago}
會指向當前分支的HEAD。
您也可以明確指定分支名稱。
git diff HEAD '[email protected]{3 weeks ago}' -- some/file/path/file.ext
在ZSH上,我遇到了'zsh:parse error near \'}''的錯誤。「有關可能會發生什麼的任何想法? – ylluminate 2012-03-11 20:05:29
'zsh'正試圖爲您解讀大括號。引用它們(在整個事物中使用雙引號,或者在每個大括號之前使用反斜槓,或者其他)。 – torek 2012-03-11 20:14:20
對,謝謝@torek。 – ylluminate 2012-03-12 21:19:00