V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
zxCoder
V2EX  ›  问与答

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

  •  
  •   zxCoder · 2021-02-21 11:05:47 +08:00 · 1180 次点击
    这是一个创建于 1131 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

    geelaw
        1
    geelaw  
       2021-02-21 11:31:22 +08:00 via iPhone
    看一下 git 的历史图不就知道了么 😅

    除了不小心提交到了主分支上,也可能是有人让远程分支倒流,然后本地也意识到了远程的倒流。
    zyfsuzy
        2
    zyfsuzy  
       2021-02-21 11:42:08 +08:00
    感觉不大可能,一定是你提交错了
    zxCoder
        3
    zxCoder  
    OP
       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
        4
    icylogic  
       2021-02-21 13:06:21 +08:00 via iPhone
    git log origin/master..HEAD
    看一下不就知道了……
    geelaw
        5
    geelaw  
       2021-02-21 15:29:46 +08:00 via iPhone
    #3 可能是在对 a 操作之前 master 已经领先 origin/master 了
    zyfsuzy
        6
    zyfsuzy  
       2021-02-22 15:26:54 +08:00
    你确定你切换到 master 分支了? 分支切换不是 git checkout 命令么? git log 看看
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3266 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 11:53 · PVG 19:53 · LAX 04:53 · JFK 07:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.