使用 git fetch 更新远程跟踪分支
使用 git fetch 更新远程跟踪分支
·
使用 git fetch 更新远程跟踪分支
获取
该命令更新您的远程跟踪分支,即,它更新存储在远程存储库中的分支的本地副本。以下命令从名为 origin 的存储库更新远程跟踪分支。git fetch
git fetch origin
fetch 命令仅更新远程跟踪分支,而不更新任何本地分支。它也不会更改 Git 存储库的工作树。因此,您可以在任何时间点运行该命令。git fetch
查看远程跟踪分支中的更改后,可以将更改合并到本地分支中,或者将本地分支的基转换为远程跟踪分支。
或者,您也可以使用该命令仅接管选定的提交。git cherry-pick commit_id
从所有远程仓库获取
该命令仅更新一个远程存储库的远程跟踪分支。如果要更新所有远程存储库的远程跟踪分支,可以使用以下命令。git fetch
# simplification of the fetch command
# this runs git fetch for every remote repository
git remote update
# the same but remove all stale branches which
# are not in the remote anymore
git remote update --prune
将远程跟踪分支与本地分支进行比较
以下代码显示了有关如何比较分支的几个选项。
# show the log entries between the last local commit and the
# remote branch
git log HEAD..origin/master
# show the diff for each patch
git log -p HEAD..origin/master
# show a single diff
git diff HEAD...origin/master
# instead of using HEAD you can also
# specify the branches directly
git diff master origin/master
上述命令显示了与原点相比,HEAD 中引入的变化。如果要查看原点与 HEAD 相比的变化,可以切换参数或使用参数。-R
将本地分支重定为远程跟踪分支
您可以将当前本地分支的基向下变基到远程跟踪分支上。以下命令对此进行了演示。
# assume you want to rebase master based on the latest fetch
# therefore check it out
git checkout master
# update your remote-tracking branch
git fetch
# rebase your master onto origin/master
git rebase origin/master
抓取与拉取的比较
该命令执行和(或基于您的 Git 设置)。不会在本地分支上执行任何操作。您始终可以运行 fetch 命令并查看传入的更改。git pullgit fetchgit mergegit rebasegit fetch
更多推荐
所有评论(0)