git 从上游更新合并冲突
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10773518/
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
Merge conflicts updating from upstream
提问by David Given
I'm trying to get started with git on a github project. (I've been using CVS, SVN and hg for years; git is hard to get my head around). I'm following the instructions as precisely as I can and simply cannot make it work.
我正在尝试在 github 项目上开始使用 git。(我多年来一直在使用 CVS、SVN 和 hg;git 很难理解)。我正在尽可能准确地遵循说明,但根本无法使其正常工作。
I clone my forked project:
我克隆了我的分叉项目:
git clone [email protected]:davidgiven/linux-allwinner.git
As recommended, I add an 'upstream' remote that tracks the project that my one is forked from:
按照建议,我添加了一个“上游”遥控器来跟踪我的项目的分支:
git remote add upstream https://github.com/amery/linux-allwinner.git
I fetch from it:
我从中获取:
git fetch upstream
All this works fine. But, it's been a week or so since I forked the project, and upstream have been making changes. So I want to pull in those changes. I'm currently in the right branch --- allwinner-v3.0-android-v2 --- so I merge from upstream into my branch:
所有这些工作正常。但是,自从我分叉该项目已经一周左右,上游一直在进行更改。所以我想引入这些变化。我目前在正确的分支 --- allwinner-v3.0-android-v2 --- 所以我从上游合并到我的分支:
git merge upstream/allwinner-v3.0-android-v2
...and I get merge conflicts.
...我遇到了合并冲突。
CONFLICT (add/add): Merge conflict in arch/arm/mach-sun5i/pm/standby/common.h
CONFLICT (add/add): Merge conflict in arch/arm/mach-sun5i/pm/standby/Makefile
CONFLICT (add/add): Merge conflict in arch/arm/mach-sun5i/pm/standby.S
CONFLICT (add/add): Merge conflict in arch/arm/mach-sun5i/pm/Makefile
[etc]
Now, I've checked in nothing; I haven't started work yet, and my project is completely untouched since I forked it. Therefore it should not be possible to have any conflicts. But there are some; what's going on, and how do I fix it?
现在,我什么也没登记;我还没有开始工作,我的项目自从我分叉后就完全没有动过。因此,应该不可能有任何冲突。但也有一些;这是怎么回事,我该如何解决?
Update:
更新:
git show-branch HEAD upstream/allwinner-v3.0-android-v2
shows this, which I have to say I don't understand a word of:
git show-branch HEAD upstream/allwinner-v3.0-android-v2
显示了这一点,我不得不说我一个字都听不懂:
! [HEAD] arm: sun3i: add getioaddr macro
! [upstream/allwinner-v3.0-android-v2] arm: sun3i: updated irq handling and machine_desc to 3.0
--
+ [upstream/allwinner-v3.0-android-v2] arm: sun3i: updated irq handling and machine_desc to 3.0
+ [upstream/allwinner-v3.0-android-v2^] arm: sunxi: renable early_printk in all _defconfig except crane's
+ [HEAD] arm: sun3i: add getioaddr macro
+ [HEAD^] arm: sun3i: add dummy machine type
回答by knittl
It could be, that upstream has rewritten history (rebase, amend, …) – they shouldn't do that, but you'll never know.
可能是上游改写了历史(rebase、修正……)——他们不应该那样做,但你永远不会知道。
Since you say you don't have any local changes or commits, you should bring your repository back to a clean state by resetting your branch:
由于您说您没有任何本地更改或提交,您应该通过重置您的分支将您的存储库恢复到干净状态:
git reset --hard upstream/allwinner-v3.0-android-v2
(This will discard any local changes and make commits of current HEAD unreachable!)
(这将丢弃任何本地更改并使当前 HEAD 的提交无法访问!)
The above assumes that you will (force) push the newly reset state of your branch to your remote repository, otherwise you will encounter the conflicts again when you try to pull from origin
.
以上假设您将(强制)将分支的新重置状态推送到远程存储库,否则在尝试从origin
.
git push origin +allwinner-v3.0-android-v2
If you already had committed yourself locally, you'd have to rebase (or cherry-pick) your commits on top of the upstream branch, and then do a push to origin. That way you will re-write your local history the same way upstream did and apply your changes on top, i.e.:
如果您已经在本地提交了自己的内容,则必须在上游分支之上重新设置(或挑选)您的提交,然后推送到原点。这样你就可以像上游一样重写你的本地历史并将你的更改应用到上面,即:
git rebase --onto upstream/branch \
last-original-upstream-commit-before-yours \
your-branch
回答by ellotheth
The show-branch
output means that upstream
and HEAD
have each added two commits since their common ancestor (assuming that's the full output). (See also: http://www.gitguys.com/topics/git-show-branch-to-see-branches-and-their-commits/) If you haven't committed anything yourself, that does mean that upstream pushed a rebase (or something else that changed the history). Since you haven't committed anything, knittl's answer is exactly what you want.
该show-branch
输出表明,upstream
与HEAD
已分别因为它们的共同祖先加两次提交(假设是完整的输出)。(另见:http: //www.gitguys.com/topics/git-show-branch-to-see-branches-and-their-commits/)如果你自己没有提交任何东西,那确实意味着上游推送变基(或其他改变历史的东西)。由于您没有做出任何事情,knittl 的答案正是您想要的。
For what it's worth, I also love git log --oneline --graph --decorate --remotes --branches
for this. You'll get an ASCII graph with all your branches and remotes, so you can visualize what happened where.
对于它的价值,我也喜欢git log --oneline --graph --decorate --remotes --branches
这个。您将获得包含所有分支和遥控器的 ASCII 图形,以便您可以直观地看到发生了什么。