[英]Dangers of 'git pull' in case the only changes to local repository come from the remote repository
我有一個用例,其中腳本需要獲取一個遠程存儲庫以獲取此遠程存儲庫中特定文件的最新版本。 拉動遠程存儲庫的通常建議是git checkout master
移至master
分支, git remote update -p
從遠程存儲庫獲取,再刪除不再在遠程中定義的分支,最后git merge --ff-only @{u}
合並更改是可能的。 但是,如果我的腳本從不在本地創建其他分支或從不添加/提交任何內容,那么我需要所有這些嗎? 我是否正確,萬一本地存儲庫的唯一更改來自遠程存儲庫,那么簡單的git pull
就足夠了嗎?
您不需要“合並”操作(“拉”暗示)。 要檢查文件是否已更新,可以使用
git fetch origin refs/heads/master
git diff --quiet FETCH_HEAD..last-check -- the-file || echo "changed"
git branch -f last-check FETCH_HEAD
git意義上的“最新修訂”( the-file
已更改的地方)是
git log --format=format:%H -1 FETCH_HEAD -- the-file
要獲取文件的內容,可以使用
git show FETCH_HEAD:the-file
要替換工作目錄中的文件(僅此一個文件),請使用
git checkout FETCH_HEAD -- the-file
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.