简体   繁体   English

将本地git仓库追赶到远程仓库

[英]Catch up local git repository to remote repository

I like to reset my local repository to catch up with the remote repository HEAD. 我想重置本地存储库以赶上远程存储库HEAD。 From Reset local repository branch to be just like remote repository HEAD and other sites, I can see the normal command set is: 重置本地存储库分支就像远程存储库HEAD和其他站点一样,我可以看到正常的命令集是:

git fetch origin
git reset --hard origin/master

However, that's still not enough for me. 但是,这对我来说还不够。 What else can I check/should I do? 我还能检查/应该做什么?

Long story, similar with Merge remote repository commits to the local , I have two local repositories say A and B . 长话短说,类似于Merge远程存储库提交到本地 ,我有两个本地存储库,分别是AB B was created from A just by copying files, well in fact, both A and B are in VM and the VM for B was duplicated from A . B从创建A只是复制文件,以及事实上,无论是AB在虚拟机和虚拟机B从复制A Both repositories A and B have the same remote git repository. 仓库AB都具有相同的远程git仓库。

The repository B lives his life - are added some patches, updated spec files, etc, while repository A stays at the point of VM duplication. 存储库B终其一生-添加了一些补丁,更新的规范文件等,而存储库A处于VM复制点。 Now I want to bring my local repository A up to where B is, via their common remote git repository. 现在,我想通过它们的公共远程git存储库将本地存储库A带到B所在的位置。 So I tried git pull first, but get Already up-to-date. 因此,我首先尝试了git pull ,但现在Already up-to-date. . Then I did the above two commands, ie, 然后我执行了以上两个命令,即

$ git fetch origin

$ git reset --hard origin/master
HEAD is now at 49e7629 - ...

at repository A . 在存储库A However, that 49e7629 HEAD is still old, comparing to repository B . 但是,与存储库B相比, 49e7629 HEAD仍旧。

The git log shows that repository B still have more updated than repository A . git log显示存储库B更新比存储库A更新更多。 What else can I check/should I do? 我还能检查/应该做什么?

Has it anything to do with how my remote git repository is configured? 与我的远程git存储库的配置有什么关系吗? Here is my remote git repository: 这是我的远程git存储库:

$ cat .git/config 
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = ssh://git@bitbucket.org/myid/myrepo.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

Thanks 谢谢

What I understand is : A and B are clones of the same distant remote repository (named origin) You want to update A with B changes 我的理解是:A和B是相同远程存储库(命名为origin)的克隆,您想用B更改来更新A

A solution for that case would be: Place yourself in A and then, add B as a remote: 对此情况的解决方案是:将自己置于A中,然后将B添加为遥控器:

git remote add originB /path/to/B/repository

You can now list your remotes: 现在,您可以列出您的遥控器了:

git remote -v

Which should print: 应该打印:

origin ssh://git@bitbucket.org/myid/myrepo.git (fetch)
origin ssh://git@bitbucket.org/myid/myrepo.git (push)
originB /path/to/B/repository (fetch)
originB /path/to/B/repository (fetch)

Now you can fetch/merge/... from originB, following the right syntax. 现在,您可以按照正确的语法从originB获取/合并/...。 For an example: 例如:

git pull originB anybranch

You will find more infos at http://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes 您可以在http://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes中找到更多信息。

Changes in Repo B need to be pushed to the shared remote in order for Repo A to pull them. 需要将存储库B中的更改推送到共享的远程服务器上,以便存储库A进行更改。 Otherwise the changes in B are local only to B. 否则,B中的更改仅对B本地。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM