在新分支 commit 之后,切换到 master 分支,为什么会提示 Your branch is ahead of 'origin/master' by 1 commit.

2021-02-21 11:05:47 +08:00
 zxCoder

先 checkout 到 feature 分支,然后提交内容,然后切换到 master 分支,为什么是提示

Your branch is ahead of 'origin/master' by 1 commit.

这个意思是本地的 master 分支领先远程 master 一个提交吗??可是我不是在 feature 分支提交的吗?要领先不也是 feature 分支领先吗?

1205 次点击
所在节点    问与答
6 条回复
geelaw
2021-02-21 11:31:22 +08:00
看一下 git 的历史图不就知道了么 😅

除了不小心提交到了主分支上,也可能是有人让远程分支倒流,然后本地也意识到了远程的倒流。
zyfsuzy
2021-02-21 11:42:08 +08:00
感觉不大可能,一定是你提交错了
zxCoder
2021-02-21 12:53:24 +08:00
@geelaw
@zyfsuzy

```
$ git switch -c a
Switched to a new branch 'a'
$ git branch
* a
dev
feature1
master
$ touch a.txt
$ git add a.txt
$ git commit -m "add a.txt"
[a fdaf3d8] add a.txt
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a.txt
$ git switch master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
```

请问这样操作哪里出问题了呢
icylogic
2021-02-21 13:06:21 +08:00
git log origin/master..HEAD
看一下不就知道了……
geelaw
2021-02-21 15:29:46 +08:00
#3 可能是在对 a 操作之前 master 已经领先 origin/master 了
zyfsuzy
2021-02-22 15:26:54 +08:00
你确定你切换到 master 分支了? 分支切换不是 git checkout 命令么? git log 看看

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/754800

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX