[英]git: cannot merge with upstream
I have made some changes on my forked repository, and I wish to overwrite a single file from upstream. 我对派生的存储库进行了一些更改,并希望从上游覆盖单个文件。 The upstream repository is added as a remote. 上游存储库将添加为远程存储库。 When I perform a merge, git tells me I am up to date: 当我执行合并时,git告诉我我是最新的:
$ git merge upstream/master master
Already up-to-date.
But when I run diff, git shows the missing file for my forked repository 但是当我运行diff时,git会显示我的分叉存储库中缺少的文件
$ git diff upstream/master origin
diff --git a/Library/Formula/exim.rb b/Library/Formula/exim.rb
deleted file mode 100644
index 48d52cf..0000000
--- a/Library/Formula/exim.rb
Is there anyway to get git to add in the missing file to my forked repository? 无论如何,有没有让git将丢失的文件添加到我的分叉存储库中?
Upstream has the file. 上游有文件。 You had it from upstream and deleted it. 您从上游获得它并删除了它。 3-way merge of no change versus delete is delete, therefore the file is still not there after the merge. 没有更改与删除的三向合并是删除,因此合并后文件仍然不存在。 Once upstream/master
is fully merged (which is the case given your first listed output), merging again is a no operation, because merge only considers changes since the branches were last merged and there are none on the other side. 一旦upstream/master
完全合并(在您的第一个列出的输出中就是这种情况),则再次合并是一个空操作,因为合并仅考虑自分支最后合并以来的更改,而另一侧则没有任何合并。
You want to either: 您想要:
revert the change in which you deleted the file: 恢复删除文件的更改:
git log -- Library/Formula/exim.rb
will tell you the revision where you removed the file and than 会告诉您修订版本中删除文件的位置,然后
git revert <revision-id>
to revert it. 还原它。
get the file's content from upstream and add it again: 从上游获取文件内容,然后再次添加:
git cat-file blob upstream/master:Library/Formula/exim.rb > Library/Formula/exim.rb git add Library/Formula/exim.rb git commit
I think you should do the merge to your local master like so : 我认为您应该像这样合并到本地主机:
git checkout master
git pull origin/master # in case there are changes posted remotely
git pull upstream/master
After that you can push your local master to the remote origin
with : 之后,您可以使用以下命令将本地主服务器推送到远程origin
:
git push origin master
At this point upstream/master
should be merged into master
, which should equal origin/master
. 此时, upstream/master
应合并到master
, master
应等于origin/master
。
Also your diff command doesn't make much sense, if you expect them to be equal : 如果您希望它们相等,那么您的diff命令也就没有多大意义了:
git diff upstream/master origin
This compares origin/master
to upstream/master
but if you made changes on your master
after you forked and you don't control upstream
these can't be equal, it seems you expect them to be. 这会将origin/master
与upstream/master
进行比较,但是如果您在分叉后对master
进行了更改,并且您无法控制upstream
,那么这些更改就不可能相等,看来您希望它们是相同的。
You're comparing upstream/master
with origin/master
, but merging upstream/master
into master
. 您正在将upstream/master
与origin/master
进行比较,但是将upstream/master
合并为master
。 It looks like you're confused between upstream
repo (the original repo on GitHub) and origin
(your forked repo on GitHub). 它看起来像你之间混淆upstream
回购(GitHub上原有的回购)和origin
(你在GitHub上叉回购)。
Once you merged changes, they're still local, if you want to make them appear in origin
you need to push them: git push origin master
. 合并更改后,它们仍然是本地的,如果要使它们出现在origin
,则需要推送它们: git push origin master
。
Graphically you have this situation at the beginning: 以图形方式,您在一开始就遇到这种情况:
A----B
\ ^master and origin/master
\---C
^upstream/master
After merge: 合并后:
A----B-----------------D
\ ^origin/master /^master
\---C---------------/
^upstream/master
And after pushing back to origin
: 在推回origin
:
A----B-----------------D
\ ^ /^master and origin/master
\---C---------------/
^upstream/master
The git merge
command is not updating the upstream repo. git merge
命令不会更新上游仓库。 You telling git to combine the changes from the upstream into your local and because you already have all the commits from the upstream in your local there is nothing to commit. 您告诉git将来自上游的更改合并到本地,并且因为您已经拥有来自本地的上游的所有提交,所以没有要提交的内容。
You want to "push" your changes. 您想“推送”您的更改。 Run git push upstream master
运行git push upstream master
http://www.lornajane.net/posts/2012/pushing-to-different-git-remotes http://www.lornajane.net/posts/2012/pushing-to-different-git-remotes
For your forked repo, you only need to do a git push origin master
to push the master branch or just a simple git push
对于您的分叉存储库,您只需要执行git push origin master
即可推送master分支或仅执行简单的git push
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.