Target
While using github to manage the project of my team, keep synchronizing with the master branch while I remain my own comment on branch "mine".
Process
- Create a test repository. Create a text file called "test" in it.
To simulate the real situation, the content of "test" is as follows:
public void function1(){
//something
}
public void function2(){
//something
}
-
Commit "test" to master branch.
-
Create a new branch called "mine".
-
Send a pull request from master to mine and merge it to branch "mine".
Now we can find document "test" in branch "mine".
-
On master branch, change the context of "text" a bit.
Commit the change.
On mine branch, add some comments to "test"
Commit the change. -
Send a pull request from master to mine.
-
On mine branch, cliclk "update from master".
The file on mine branch becomes as follows:
While the file on master branch keeps unchanged:
Edit conflict manually
Normally, git will automatically merge the difference of mine branch and master branch, but there are also some conflicts that can not be dealt with automatically. Example:
- "test.txt" on mine branch:
while "text.txt" on master branch is as follows:
- Change the file on master branch as follows:
private void function1(){
//something
}
public void function2(){
//other things
}
- Send pull request from master to mine.
- Update mine branch, now conflict happens:
- Calm down and edit the file. Be sure to remain both the change from master branch and mine branch.
//This is the first function
private void function1(){
//something
}
public void function2(){
//other things
}
- Commit. Done!
Conclusion
It's easy to keep one`s own addiction while synchronizing with the master branch. "Merge" function will automatically deal with the conflict between the pull request and local files, although there may also be some conflicts that have to be solved by the programmer's own hand.