我和我的朋友,我们正在制作某种项目,我们将GIT用于我们的版本控制软件,但是在我从gitlab中提取他的代码,并进行了一些更改并提交了这些更改后,我想推回gitlab,但是当那时,这个警告和错误:
warning: redirecting to https://gitlab.com/Sanady/project.git/
To https://gitlab.com/Sanady/project
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitlab.com/Sanady/project'
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旗(强制)推动回购,但仍然不起作用。。。
假设没有权限问题之类的(我不熟悉gitlab),
看起来您的朋友也将更改提交给了master,因此您的本地更改不包括他的工作。所以应该先执行以下操作:
// Note, make sure you don't have uncommitted files:
git status
// now run the following:
git pull --rebase
这将拉动您朋友的更改,并将您的本地提交放在上面。请注意,如果您和您的朋友正在接触相同的文件,您可能会遇到“冲突解决”。Git不知道如何在同一个文件上“相邻”应用您和您朋友的更改。
假设没有这样的冲突:
然后您可以尝试推动:
git push
此错误意味着您的朋友在拉取时间和提交更改时间之间提交了一些更改。
因此,您需要首先拉动更改,解决冲突,然后才能推动:
git pull
# resolve conflicts (see git status)
git commit # commit merge
git push # now it works