git:如何同步到最新版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12425500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:30:00  来源:igfitidea点击:

git: how to sync to latest revision

git

提问by PaulJ

Warning: git novice here.

警告:这里是 git 新手。

I have downloaded the source code of an open-source project (ffmpeg, to be exact) using git (git clone). I checked out an older revision in order to do test it (git checkout [version number]), and git told me that I'm now in a detached HEAD state. Now I want to resync again to the latest remote revision, but I don't know how.

我已经使用 git ( git clone)下载了一个开源项目(准确地说是 ffmpeg)的源代码。我检查了一个较旧的修订版以对其进行测试 ( git checkout [version number]),并且 git 告诉我我现在处于分离的 HEAD 状态。现在我想再次重新同步到最新的远程修订版,但我不知道如何。

I don't want to create any local branches. I haven't made any local changes that I want to keep. I don't want to do any of those fancy things that git can do when you are a serious developer (which I'm not). I just want my local source tree to be the same than the latest remote version.

我不想创建任何本地分支。我没有进行任何想要保留的本地更改。当你是一个认真的开发者(我不是)时,我不想做任何 git 可以做的花哨的事情。我只希望我的本地源代码树与最新的远程版本相同。

git checkout .doesn't do anything. git pulltells me that I'm not currently on a branch. Short of erasing everything and do a git cloneagain, what else can I do?

git checkout .什么都不做。git pull告诉我我目前不在分支机构。除了擦除所有内容并git clone再次执行,我还能做什么?

回答by Christopher

I don't want to create any local branches.

我不想创建任何本地分支。

Sure you do. You just want a "local tracking branch", which is a branch that tracks a remote branch, making it easy to stay up to date with the project.

你当然知道。您只需要一个“本地跟踪分支”,它是一个跟踪远程分支的分支,可以轻松地与项目保持同步。

Try this:

尝试这个:

git checkout master ;# you should have a 'master' branch by default
git pull ;# to get the newest changes from the remote repo

Issue git pullon that branch anytime you want to stay up to date with the remote. You can see how local tracking branches are configured using git remote show origin, and I strongly recommend spending a little time in the git-scm docseven if you don't want to do fancy git stuff. A little background knowledge will help you navigate that source tree nearly any way you want.

git pull只要您想与遥控器保持同步,就可以随时在该分支上发布问题。您可以使用 来查看本地跟踪分支是如何配置的git remote show origin,我强烈建议您花一点时间在git-scm 文档中,即使您不想做花哨的 git 东西。一点背景知识将帮助您几乎以任何您想要的方式浏览该源代码树。