如何保持 GIT 存储库同步

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4975928/
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 05:02:51  来源:igfitidea点击:

How to keep the GIT repos in sync

git

提问by amok

I don't grasp GIT yet. So I have a basic question:

我还没有掌握 GIT。所以我有一个基本的问题:

I want to keep one of the repos that I am using (I don't own it, I cloned it) in sync with my local copy.

我想保持我正在使用的存储库之一(我不拥有它,我克隆了它)与我的本地副本同步。

How do I do that?

我怎么做?

I am aware of git fetch/pull but when I do run that in the same folder where I executed git clone http://.....gitI get the following error

我知道 git fetch/pull 但是当我在执行 git clone http://.....git的同一文件夹中运行它时,我收到以下错误

fatal: Not a git repository (or any of the parent directories): .git

致命:不是 git 存储库(或任何父目录):.git

Thanks, mE

谢谢,我

回答by markdorison

git fetchwill retrieve all changes from the remote.

git fetch将从远程检索所有更改。

git pullwill merge those changes from the remote into your local copy (this accomplishes two commands in one step. fetch & merge

git pull将从远程合并这些更改到您的本地副本(这一步完成两个命令。 fetch & merge

If you have commit access to the remote repository, git pushwill push your local changes to the origin that you cloned from.

如果您对远程存储库具有提交访问权限,git push则会将您的本地更改推送到您从中克隆的源。

回答by Ilya Ivanov

Git clone creates a new directory for cloned repo. You need to go into it first. For example:

Git clone 为克隆的 repo 创建一个新目录。你需要先进入它。例如:

$ git clone git://github.com/git/hello-world.git
$ cd hello-world
$ git fetch

回答by Miles Strombach

Git fetch will download all of the changes that exist on the remote, but won't update your working tree. Git pull will download changes and if you're on a local branch tracking a remote branch, will update it for you.

Git fetch 将下载远程存在的所有更改,但不会更新您的工作树。Git pull 将下载更改,如果您在跟踪远程分支的本地分支上,则会为您更新它。