【问题标题】:Fixing issue with Github repo edit and local repo [duplicate]修复 Github 存储库编辑和本地存储库的问题 [重复]
【发布时间】:2023-03-27 11:51:01
【问题描述】:

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

我尝试使用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.

【问题讨论】:

  • 您必须在 GitHub 上将您的工作(本地)与“他们的”(您的)工作结合起来。要么,要么您可以使用git push --force 丢弃“他们的”工作(即您在 GitHub 上的工作)。但大概你想保留你的工作,以及你的工作。考虑使用git fetch,后跟git mergegit rebase

标签: git github


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2021-11-02
    • 2013-10-10
    • 2020-07-16
    • 1970-01-01
    • 2012-03-04
    • 2016-02-13
    • 2013-02-14
    • 2020-09-13
    • 1970-01-01
    相关资源
    最近更新 更多