我有一个本地存储库,我想将其推送到 github。但它不会推送,因为它认为工作树是干净的。
这是输出:
shmuel@nixos ~/nixos master ± git add . && git commit -m config && git push origin master
[master ab79eda] config
1 file changed, 1 insertion(+)
To github.com:shmu26/NIX.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'github.com:shmu26/NIX.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
✘ shmuel@nixos ~/nixos master git add . && git commit -m config && git pull origin master
On branch master
nothing to commit, working tree clean
✘ shmuel@nixos ~/nixos master git add . && git commit -m config && git push origin master
On branch master
nothing to commit, working tree clean
我设置了凭据,但是当我尝试推送时,它说我首先需要拉取。 所以我拉。 然后,当我再次尝试推动时,它说树是干净的。所以什么都不会被推动。
git pull 命令实际上是另外两个命令的组合,即 git fetch 和 git merge。在操作的第一阶段, git pull 将执行 git fetch ,其范围仅限于 HEAD 所指向的本地分支。下载内容后,git pull 将进入合并工作流程。将创建一个新的合并提交并更新 HEAD 以指向新的提交。 来源
因此,在运行
git pull
命令后,git 将创建一个新的合并提交(如果没有合并冲突)。
因此,您的工作树是干净的,无法暂存或提交。 如果您同意 git 创建的提交,您应该将其推送到远程
git pull origin master && git push origin master
如果不是你想要的,你可以使用
git fetch
并根据需要合并。
或者您可以使用 rebase
选项作为 this 答案 中的概述
git pull --rebase <remote-name> <branch-name>