git将更改推送到master,而不会覆盖其他人完成的工作

时间:2013-05-29 10:10:09

标签: git push

通常我会将代码推送到'master'分支:

git add . 
git commit -m "message"
git push

工作完美,所有内容都保存最新。

现在其他人已经从另一个地方完成了对'master'的工作。

如何将我的更改推送到master,而不会覆盖他的更改 - 将代码更改保留在其提交中?

当我做正常的git推送时,我得到了:

christophecompaq@ubuntu:~/Populisto$ git push
To git@github.com:Christophe1/Populisto.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:Christophe1/Populisto.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.
christophecompaq@ubuntu:~/Populisto$ 

如果我使用'git push -f',那不会覆盖他所做的一切吗?

感谢。

1 个答案:

答案 0 :(得分:3)

在执行git push之前,您必须执行git pull。其他人的工作必须首先与您的代码合并,然后您可以将更改推送到存储库。 git pull将保留您更新的代码,并且仅添加/更新代码(意味着git将合并代码)来自上次提交(其他人的代码)。

如果两个开发人员都使用同一段代码,那么git将显示冲突,这些冲突必须首先解决

相关问题