您的分支领先 'origin/branch' 1 次提交

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

我知道这个问题已经在SO中讨论了很多。但请多多包涵。

我的上级创建了一个名为 mav921 的分支,我被指示检查该分支并在其上工作。

所以我所做的是,git checkout -b local-mav921 origin/mav921

成功了。

当我在 local-mav921 分支完成我的任务时,我想推送它,所以我做了

git add .
git commit -m "message"

但是提交说:

Your branch is ahead of 'origin/mav921' by 1 commit.
(use "git push" to publish your local commits)

Changes not staged for commit:
... all the files that I was working.

基本上是在运行add & commit之后发生的事情,没有提交我的工作。

所以,我尝试按照错误消息推送:git push,它说:

fatal: The upstream branch of your current branch does not match
the name of your current branch.  To push to the upstream branch
on the remote, use

git push origin HEAD:mav921

To push to the branch of the same name on the remote, use

git push origin HEAD

当 运行 git branch -a:

    Mav921
    mav921
*   local-mav921
    master
    remotes/origin/mav921
    remotes/origin/master

你可以注意到我有 Mav921(不要介意,因为我是从 master 那里创建的)。
。 另外,mav921(这是因为我从远程检查了那个,而没有创建一个基于该分支的新分支)。 最后,local-mav921(是 运行 git checkout -b local-mav921 origin/mav921 的结果)

老实说,我不知道如何解决这个问题。如果有人能告诉我发生了什么以及如何解决这个问题,那就太好了。

So what I did was, git checkout -b local-mav921 origin/mav921

所以现在您的本地分支与其跟踪的远程分支具有不同的名称。这很不寻常,但既不违法也不致命。但这确实意味着某些 Git 快捷命令将不起作用。

Basically, what happened is after running add & commit, it did not commit my work.

是的。它很好地完成了你的工作。这就是为什么您领先于遥控器;你做了一个新的提交。

I tried to push as per error message: git push, and it says: fatal: The upstream branch of your current branch does not match the name of your current branch

确实如此。正如我一开始所说,你做了一件不同寻常的事。您的本地和远程分支名称不匹配。这意味着像简单的 git push 这样的快捷方式不起作用。因此,您必须以完整形式给出命令。但这没问题!这简单。该消息会准确告诉您如何操作:

git push origin HEAD:mav921

那就这样吧。