git 您的分支落后于 2 个提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28152210/
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
your branch is behind by 2 commits
提问by RSM
I have a branch of my master branch called 218.
我的主分支有一个分支,名为 218。
I am the only one using this branch.
我是唯一一个使用这个分支的人。
I commit my changes 3 weeks ago looking to do a pull request, but it was rejected as I needed to make changes.
我在 3 周前提交了我的更改,希望做一个拉取请求,但由于我需要进行更改而被拒绝。
Now I have made those changes and I wanted to commit the latest changes to my branch.
现在我已经进行了这些更改,并且我想将最新的更改提交到我的分支。
I tried to commit and it told me I needed to merge and pull. So I did, and it messed up all my files and got rid of my changes I made in the last 3 weeks.
我尝试提交,它告诉我我需要合并和拉取。所以我这样做了,它弄乱了我所有的文件并摆脱了我在过去 3 周内所做的更改。
I undid this by: git reset --hard HEAD~1
我通过以下方式取消了此操作: git reset --hard HEAD~1
And now as it stands in my repo on my computer all the files are how they should be. But when I do git status, my changes dont show and it says:
现在,就在我计算机上的存储库中,所有文件都是它们应有的样子。但是当我执行 git status 时,我的更改没有显示,它说:
Your branch is behind 'origin/feature/218' by 2 commits, and can be fast forwarded. nothing to commit, working directory clean.
I want to make the branch what I have currently in my repo on my local computer as it stands and not pull anything down but overwrite everything with what I have locally.
我想使分支成为我当前在本地计算机上的回购中拥有的分支,而不是拉下任何东西,而是用我在本地拥有的东西覆盖所有内容。
How do I do this?
我该怎么做呢?
回答by Schleis
Since you are the only one working on the branch, you can overwrite the state of the remote branch by doing git push --force
.
由于您是唯一一个在分支上工作的人,因此您可以通过执行 来覆盖远程分支的状态git push --force
。
Though are you sure that you are the only one that is on the branch? If you were the only one working on the branch, only your commits would have been on the remote and you would have had no need to do a git pull
.
虽然你确定你是唯一一个在分支上的人吗?如果你是唯一一个在分支上工作的人,那么只有你的提交会在远程上,你就不需要做一个git pull
.
Doing git push --force
with a shared branch will cause much more trouble for your team. So make sure that you want to remove the 2 commits that are on the remote branch by doing the following:
这样做git push --force
有一个共享的分支将导致你的团队更麻烦。因此,请确保您要通过执行以下操作来删除远程分支上的 2 个提交:
git checkout origin/feature/218
git log -3
This will show that last three commits (the 2 you are behind and the last one you share) on the remote make sure that they are yours and that you want the last 2 to be overwritten.
这将显示远程上的最后三个提交(您落后的 2 个和您共享的最后一个)确保它们是您的并且您希望最后 2 个被覆盖。
回答by Yogesh Kaushik
git pull --rebase
I guess this will solve the problem.
我想这将解决问题。
回答by Bayram Binbir
If your branch is behind by master then do:
如果您的分支落后于 master,则执行以下操作:
git checkout master (you are switching your branch to master)
git pull
git checkout yourBranch (switch back to your branch)
git merge master
After merging it, check if there is a conflict or not.
If there is NO CONFLICT then:
合并后,检查是否有冲突。
如果没有冲突,则:
git push
If there is a conflict then fix your file(s), then:
如果存在冲突,则修复您的文件,然后:
git add yourFile(s)
git commit -m 'updating my branch'
git push