当运行git状态时,我得到以下信息

Your branch is ahead of 'origin/master' by 3 commits.

我在其他一些帖子上读过,解决这个问题的方法是运行git拉—rebase,但rebase到底是什么,我会丢失数据吗,还是这是与主同步的简单方法?


当前回答

这条来自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的消息意味着您已经在本地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 rebase -i origin/master

通过这种方式,我可以看到提交,并决定放弃它或选择…

我有这个问题,我使用'git重置-硬起源/主',没有引号,将我的本地主基到远程主分支。

如果你的git说你是提前提交,那么只是 首先,

Git推源

确保你已经把你所有的最新工作在回购

然后,

Git重置-硬源/主

重置和匹配回购

没有什么可以解决的。您只是进行了3次提交,还没有将它们移动到远程分支。有几个选项,取决于你想做什么:

Git push:将更改移动到远程(如果远程上已经有其他更改,这可能会被拒绝) 什么都不做,继续编码,改天再同步 Git pull:从远程获取更改(如果有的话),并将它们合并到您的更改中 Git pull——rebase:如上所述,但尝试在远程更改之上重做你的提交

您处于典型的情况(尽管通常在大多数工作流中您不会在master上投入很多)。下面是我通常会做的事情:检查我的更改。也许可以做一个git rebase -interactive在它们上做一些修饰,删除那些糟糕的,重新排序使它们更有逻辑。现在用git push将它们移动到远程。如果这被拒绝,因为我的本地分支不是最新的:git拉-rebase重做我的工作在最近的变化和git推再次。