两个人在 git 中同时处理一个文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8508861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:30:11  来源:igfitidea点击:

Two people working on a file at the same time in git

gitgithub

提问by vanneto

Possible Duplicate:
How git works when two peers push changes to same remote simultaneously

可能的重复:
当两个对等方同时将更改推送到同一个远程时,git 如何工作

I'm kinda new to git and me and a friend want to do some collaborative developing with git. I got the whole pull and push system down somewhat, now I have a question.

我对 git 有点陌生,我和一个朋友想用 git 进行一些协作开发。我稍微降低了整个拉推系统,现在我有一个问题。

I want to work on file test.phpand I pull for new changes. Nothing. I edit it and want to push it, but in this time my friend edited and pushed it. What happens now? How are these conflicts solved?

我想处理文件test.php并拉取新的更改。没有。我编辑它并想推送它,但这次我的朋友编辑并推送了它。现在会发生什么?这些冲突如何解决?

Thank you!

谢谢!

回答by Massimiliano Peluso

the procedure should be the below:

程序应如下:

  • pull the file
  • edit it
  • commit it(it commits to your local repository)
  • pull it again (if there are any conflict you will Be notified) in that case you can solve it executing the below command(GitBash on your repository working folder):

    git mergetool

  • 拉取文件
  • 编辑它
  • 提交它(它提交到您的本地存储库)
  • 再次拉取它(如果有任何冲突,您将收到通知),在这种情况下,您可以执行以下命令(您的存储库工作文件夹中的 GitBash)解决它:

    git合并工具

it will run the merging tool you got configured in your .gitconfig file

它将运行您在 .gitconfig 文件中配置的合并工具

after that you can push your changes

之后,您可以推送您的更改