git 您的分支领先于 'origin/master' 3 次提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16288176/
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 ahead of 'origin/master' by 3 commits
提问by FluxEngine
I am getting the following when running git status
运行时我得到以下信息 git status
Your branch is ahead of 'origin/master' by 3 commits.
I have read on some other post the way to fix this is run git pull --rebase
but what exactly is rebase, will I lose data or is this simple way to sync with master?
我已经在其他一些帖子中阅读了修复此问题的方法,git pull --rebase
但究竟什么是 rebase,我会丢失数据还是这种与 master 同步的简单方法?
回答by iberbeu
You get that message because you made changes in your local master and you didn't push them to remote. You have several ways to "solve" it and it normally depends on how your workflow looks like:
您收到该消息是因为您在本地 master 中进行了更改,并且没有将它们推送到远程。您有多种“解决”方法,这通常取决于您的工作流程:
- In a good workflow your remote copy of master should be the good one while your local copy of master is just a copy of the one in remote. Using this workflow you'll never get this message again.
- If you work in another way and your local changes should be pushed
then just
git push origin
assuming origin is your remote - If your local changes are bad then just remove them or reset your
local master to the state on remote
git reset --hard origin/master
- 在一个好的工作流程中,您的 master 的远程副本应该是好的,而 master 的本地副本只是远程副本的副本。使用此工作流程,您将永远不会再收到此消息。
- 如果您以另一种方式工作并且应该推送您的本地更改,那么
git push origin
假设 origin 是您的遥控器 - 如果您的本地更改不好,那么只需删除它们或将您的本地主服务器重置为远程状态
git reset --hard origin/master
回答by pmr
There is nothing to fix. You simply have made 3 commits and haven't moved them to the remote branch yet. There are several options, depending on what you want to do:
没有什么可以解决的。您只是进行了 3 次提交,但尚未将它们移动到远程分支。有多种选择,具体取决于您要执行的操作:
git push
: move your changes to the remote (this might get rejected if there are already other changes on the remote)- do nothing and keep coding, sync another day
git pull
: get the changes (if any) from the remote and merge them into your changesgit pull --rebase
: as above, but try to redo your commits on top of the remote changes
git push
:将您的更改移动到遥控器(如果遥控器上已经有其他更改,这可能会被拒绝)- 什么都不做,继续编码,改天同步
git pull
:从远程获取更改(如果有)并将它们合并到您的更改中git pull --rebase
:如上所述,但尝试在远程更改之上重做您的提交
You are in a classical situation (although usually you wouldn't commit a lot on master in most workflows). Here is what I would normally do: Review my changes. Maybe do a git rebase --interactive
to do some cosmetics on them, drop the ones that suck, reorder them to make them more logical. Now move them to the remote with git push
. If this gets rejected because my local branch is not up to date: git pull --rebase
to redo my work on top of the most recent changes and git push
again.
您处于经典情况(尽管通常在大多数工作流程中您不会在 master 上提交很多内容)。这是我通常会做的事情: 查看我的更改。也许git rebase --interactive
对它们做一些化妆品,丢弃那些糟糕的东西,重新排列它们以使它们更合乎逻辑。现在使用 将它们移动到遥控器git push
。如果这因为我的本地分支不是最新的而被拒绝:git pull --rebase
在最近的更改之上重做我的工作git push
。
回答by Abhishek Goel
Use these 4 simple commands
使用这4个简单的命令
Step 1: git checkout <branch_name>
第 1 步:git checkout <branch_name>
This is obvious to go into that branch.
进入那个分支是显而易见的。
Step 2: git pull -s recursive -X theirs
第 2 步:git pull -s recursive -X theirs
Take remote branch changes and replace with their changes if conflict arise.
Here if you do git status
you will get something like this your branch is ahead of 'origin/master' by 3 commits.
如果发生冲突,进行远程分支更改并替换它们的更改。在这里,如果你这样做,git status
你会得到这样的东西,你的分支比'origin/master'领先3次提交。
Step 3: git reset --hard origin/<branch_name>
第 3 步:git reset --hard origin/<branch_name>
Step 4: git fetch
第 4 步:git fetch
Hard reset your branch.
硬重置你的分支。
Enjoy.
享受。
回答by pragman
Came across this issue after I merged a pull request on Bitbucket.
我在 Bitbucket 上合并了一个拉取请求后遇到了这个问题。
Had to do
不得不做
git fetch
and that was it.
就是这样。
回答by Alex
Usually if I have to check which are the commits that differ from the master I do:
通常,如果我必须检查哪些提交与主提交不同,我会这样做:
git rebase -i origin/master
In this way I can see the commits and decide to drop it or pick...
通过这种方式,我可以看到提交并决定放弃它还是选择......
回答by Sylvain Defresne
This message from git
means that you have made three commits in your local repo, and have not published them to the master
repository. The command to run for that is git push {local branch name} {remote branch name}
.
此消息来自git
意味着您已在本地master
存储库中进行了三个提交,并且尚未将它们发布到存储库。为此运行的命令是git push {local branch name} {remote branch name}
.
The command git pull
(and git pull --rebase
) are for the other situation when there are commit on the remote repo that you don't have in your local repo. The --rebase
option means that git
will move your local commit aside, synchronise with the remote repo, and then try to apply your three commit from the new state. It may fail if there is conflict, but then you'll be prompted to resolve them. You can also abort the rebase
if you don't know how to resolve the conflicts by using git rebase --abort
and you'll get back to the state before running git pull --rebase
.
命令git pull
(和git pull --rebase
) 用于另一种情况,当您在本地存储库中没有远程存储库上的提交时。该--rebase
选项意味着git
将您的本地提交移到一边,与远程存储库同步,然后尝试从新状态应用您的三个提交。如果存在冲突,它可能会失败,但随后会提示您解决它们。rebase
如果您不知道如何通过使用解决冲突,您也可以中止git rebase --abort
,您将回到运行前的状态git pull --rebase
。
回答by Pratik Khadka
If your git says you are commit ahead then just First,
如果你的 git 说你提前提交了,那么首先,
git push origin
git push 原点
To make sure u have pushed all ur latest work in repo
确保你已经在 repo 中推送了你所有的最新工作
Then,
然后,
git reset --hard origin/master
git reset --hard origin/master
To reset and match up with the repo
重置并与 repo 匹配
回答by Sudhir Vishwakarma
This happened to me once after I merged a pull request on Bitbucket.
我在 Bitbucket 上合并了一个拉取请求后,这发生在我身上。
I just had to do:
我只需要这样做:
git fetch
git fetch
My problem was solved. I hope this helps!!!
我的问题解决了。我希望这有帮助!!!
回答by sandes
$ git fetch
- remote: Enumerating objects: 3, done.
- remote: Counting objects: 100% (3/3), done.
- remote: Compressing objects: 100% (3/3), done.
- remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
$ git pull
- Already up to date!
- Merge made by the 'recursive' strategy.
finally:
最后:
$ git push origin