nothing to commit, working tree clean F:\gif-compression-react-nest>git push origin -u…
- User
nothing to commit, working tree clean
F:\gif-compression-react-nest>git push origin -u main To https://github.com/zjrwtxdaydayup/gif_compression.git ! [rejected] main -> main (non-fast-forward) error: failed to push some refs to 'https://github.com/zjrwtxdaydayup/gif_compression.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.
F:\gif-compression-react-nest>git pull fatal: refusing to merge unrelated histories
- Assistant
The error message "
! [rejected] main -> main (non-fast-forward)" followed by "" means that you're trying to push your commits to a remote branch which has commits that you do not have locally. Git is protecting you from losing work by rejecting the push. - User
用中文回答我
- Assistant
出现 "
! [rejected] main -> main (non-fast-forward)" 和 "error: failed to push some refs to 'https://github.com/zjrwtxdaydayup/gif_compression.git'" 的错误信息表示你试图将你的更改推送到远程分支,但是那个分支包含了你本地所没有的提交。Git 为了防止你丢失工作内容,所以拒绝了你的推送。提示 "
Updates were rejected because the tip of your current branch is behind its remote counterpart" 暗示你在再次推送之前需要从远端仓库获取并整合这些更改。而在尝试运行
git pull后出现的fatal: refusing to merge unrelated histories错误信息则表明,你的本地仓库与远程仓库之间不存在共同的提交历史。如果这两个仓库是独立开始的,或者远程仓库的历史被重写了,就会出现这种情况。针对这个问题,你有几个解决方案:
-
在拉取操作时使用
--allow-unrelated-histories标志shellF:\gif-compression-react-nest>git pull origin main --allow-unrelated-histories这将允许 Git 合并两个不相关的历史,但你可能仍然会遇到需要手动解决的合并冲突。
-
强制推送你的本地更改(如果你完全确定) 如果你确定你的本地仓库是应该在远程存在的,并且可以安全地覆盖远程的历史,你可以执行强制推送。但是,这将覆盖远程仓库,并且远程的任何更改都会丢失。
-