git 推送:对以下文件的本地更改将被合并覆盖

git push: local changes to the following files would be overwritten by merge

我在使用 Git 进行的项目中遇到了一些问题。我为此使用了一个非裸存储库。

提交一些本地更改后,当我 运行:

git status

我得到:

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

没有错。但是当尝试将本地提交的更改推送到远程存储库时:

git push origin master

我收到下一条错误消息:

Branch master -> FETCH_HEAD Error: Your local changes to the following files would be overwritten by merge. Please, commit your changes or stash them before you can merge. Aborting

当我运行

git status 

之后我得到:

Your branch is up-to-date with ‘origin/master’

但是,当我查看我的远程存储库时,我并没有真正提取这些更改。

很多人都遇到过同样的问题,但它总是在拉取请求之后从来没有,这似乎更有意义,从来没有在推送之后。另外,我没有任何承诺。

我知道这可能是一个简单而明显的问题,但是,你试图推送到 master 的分支是什么?你在当地的主分支工作吗?如果你在另一个本地不是 master 的分支,你的推送将忽略当前分支的更改。

我知道我问这个问题已经有一段时间了,但问题与我从未听说过的一位同事在远程存储库上设置的挂钩有关。