两个人开发一个项目,用的Git做版本控制,两个人同时都有代码要提交到已有的远端仓库里面,这个步骤应该是怎样的呢?
例如下面一个场景该如何处理?(只用了一个分支master)
开发人员1:git clone ...
开发人员2:git clone ...
开发人员1:编码...
开发人员2:编码...
开发人员1:git add -> git commit -> git push (ok)
开发人员2:git add -> git commit -> git push (失败!)
当一个人push成功后,另一个人再push就不可以了。 现在我们的处理办法是,开发人员2重新Clone一次,手动增加代码,再提交,push。但是这样做太麻烦了,正确的做法应该是怎样呢?
PHPz2017-04-22 09:01:27
Clone is a one-time use, and will be used by anyone in subsequent development:
If git push fails:
Recommend this book: http://git-scm.com/book/zh
巴扎黑2017-04-22 09:01:27
The above problem can be solved using git pull
或者 git fetch
. If you want to use git better,
It is recommended to use Git Flow, which is an excellent Git branch model methodology. Full compliance with this set of rules can avoid common problems and bring a smooth development experience. This can be said to be best practice
github: https://github.com/nvie/gitflow
Related articles:
Start practicing git-flow http://www.jeffkit.info/2010/12/842/
Git flow development process http://ihower.tw/blog/archives/5140/
http://nvie.com/posts/a-successful-git-branching-model/
Git branch management strategy http://www.ruanyifeng.com/blog/2012/07/git.html
git flow and github flow http://hooopo.writings.io/articles/fe2b0791
高洛峰2017-04-22 09:01:27
Tell me two disadvantages of your approach.
1. There is only one master version. Usually we have two versions, a master version and a work version.
The master version is equivalent to the official version. Basically, dozens of files are updated together every time it is updated. The work version is equivalent to the test version, and it is normal to update it 20 times a day.
2. You mentioned that two people, a and b, submitted questions at the same time. Under normal circumstances, a should be submitted, and then b will merge (merge) a's submission, first test whether your project can still work normally locally, and finally b will be submitted.
The second point is the soul of git, and it is also something that many people are not used to. The biggest advantage of git's design is that it ensures that every submitted version is runnable, so that no matter you delete a certain version, there will be no problems on the entire update line. Because future versions can still run.
Therefore, there is a default prerequisite for using git. First, the version submitted by everyone should run correctly on their own machine. What I'm talking about here about running correctly is not just the code I modified, but also the one after merging other people's updates. In other words, every submission is actually a integrity test. Anyone who develops knows that the initial environment configuration is indispensable for any project. If the project cannot run during development, there is basically no need to modify the code. Therefore, it is very necessary to maintain the integrity of the project.
PHP中文网2017-04-22 09:01:27
Developer 1: git add -> git commit -> git push (ok)
Developer 2: git add -> git commit -> git pull origin master -> git commit -a -m 'merge' -> git push
天蓬老师2017-04-22 09:01:27
The two of them don’t even know the most basic process of git, and they don’t know how to read the error messages git gives when encountering problems. How did they choose to use git in the first place? Are you following the crowd?