【发布时间】:2022-01-23 06:00:54
【问题描述】:
我在尝试将我的分支推送到 Git 时遇到了一些问题,并且无法找到我可以遵循的直截了当的答案。
我下载了一个克隆的存储库并做了一些更改。然后,我在 Github 上创建了一个名为“features/library”的新分支。
然后我完成了:
git switch features/librarygit statusgit add *git commit -am 'My message'git branch --set-upstream-to origin feature/librarygit push origin features/library
我收到以下错误:
! [rejected] feature/library -> feature/library (non-fast-forward)
error: failed to push some refs to 'https://github.com/my/repo.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 推送提交,而不是文件。这意味着您需要准确了解什么是提交、Git 如何找到提交以及 Git 如何处理提交。请参阅Timothy Truckle's answer 以获得非常简短的概述:其中的小写字母代表提交。
标签: git github command-line-interface version github-for-windows