当运行git状态时,我得到以下信息
Your branch is ahead of 'origin/master' by 3 commits.
我在其他一些帖子上读过,解决这个问题的方法是运行git拉—rebase,但rebase到底是什么,我会丢失数据吗,还是这是与主同步的简单方法?
当运行git状态时,我得到以下信息
Your branch is ahead of 'origin/master' by 3 commits.
我在其他一些帖子上读过,解决这个问题的方法是运行git拉—rebase,但rebase到底是什么,我会丢失数据吗,还是这是与主同步的简单方法?
当前回答
我有这个问题,我使用'git重置-硬起源/主',没有引号,将我的本地主基到远程主分支。
其他回答
您会收到这条消息,因为您在本地主服务器中进行了更改,而没有将它们推到远程。你有几种方法来“解决”它,这通常取决于你的工作流是什么样子的:
在一个好的工作流程中,master的远程副本应该是好的,而master的本地副本只是远程副本的副本。使用此工作流,您将永远不会再次收到此消息。 如果你以另一种方式工作,你的局部变化应该被推动 然后git push origin,假设origin是你的遥控器 如果您的本地更改是坏的,那么只需删除它们或重置您的 本地主到远程git重置的状态——硬源/主
这条来自git的消息意味着您已经在本地repo中进行了三次提交,并且还没有将它们发布到主存储库。要运行的命令是git push{本地分支名称}{远程分支名称}。
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重置-硬源/主
使用这个命令
我在Bitbucket上合并了一个pull请求后遇到了这个问题。
不得不做
git fetch
就是这样。
没有什么可以解决的。您只是进行了3次提交,还没有将它们移动到远程分支。有几个选项,取决于你想做什么:
Git push:将更改移动到远程(如果远程上已经有其他更改,这可能会被拒绝) 什么都不做,继续编码,改天再同步 Git pull:从远程获取更改(如果有的话),并将它们合并到您的更改中 Git pull——rebase:如上所述,但尝试在远程更改之上重做你的提交
您处于典型的情况(尽管通常在大多数工作流中您不会在master上投入很多)。下面是我通常会做的事情:检查我的更改。也许可以做一个git rebase -interactive在它们上做一些修饰,删除那些糟糕的,重新排序使它们更有逻辑。现在用git push将它们移动到远程。如果这被拒绝,因为我的本地分支不是最新的:git拉-rebase重做我的工作在最近的变化和git推再次。