首页 > 解决方案 > 修复 Github repo 编辑和本地 repo 的问题

问题描述

我遇到了一个问题,文件大小写的更改不会推送到我的远程仓库。

我尝试使用git mv更改标题,但它不起作用。我在 GitHub 上更改了文件的名称,并将更改提交到了 repo。现在我的本地仓库不会将更改推送到远程。

我不愿意将较旧的提交拉入我的本地仓库,因为我做了很多我不想丢失并且无法远程提交的更改。有没有办法解决?

cd would-you-rather
git add .
git commit -m '9th commit'
On branch main
Your branch and 'origin/main' have diverged,
and have 3 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)
nothing to commit, working tree clean
 git push  
To https://github.com/xxxx/xxx.git
 ! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/xxx/xxx.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

标签: gitgithub

解决方案


我认为您在 Github 网络上更改了一些内容,但您还没有下载它。我通常会看到这种情况,例如,我在 Github Web UI 中更改了 README 文件,保存,然后在本地更改了一些文件,并且想要推送。由于在网络中对 README 进行了更改,而我还没有下载它,因此我们存在冲突/分歧。

您可能希望将本地更改移动到另一个分支,例如temp,签出到 master、pull 和 rebasetemp到 master,因此它们被合并了。一切都很干净。如果您想重置您在 master 中的最后一次提交以将它们“释放”到暂存区,reset --soft HEAD~1可以。然后你可以看到你的最后一次提交现在处于未提交状态。然后你可以checkout -b tempcommit -m你的本地更改,并检查回 master,pull然后重新定位tempmaster.


推荐阅读