[英]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.