1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

master branchと同調しながら、自分特別なコマンドなどを維持する

Last updated at Posted at 2016-08-30

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".
git.png

Process

  1. 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
}
  1. Commit "test" to master branch.

  2. Create a new branch called "mine".

  3. Send a pull request from master to mine and merge it to branch "mine".
    Now we can find document "test" in branch "mine".
    text.PNG

  4. On master branch, change the context of "text" a bit.
    changeinmaster.PNG
    Commit the change.
    On mine branch, add some comments to "test"
    changemine.PNG
    Commit the change.

  5. Send a pull request from master to mine.

  6. On mine branch, cliclk "update from master".
    The file on mine branch becomes as follows:
    merge.PNG
    While the file on master branch keeps unchanged:
    mastersame.PNG

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:

  1. "test.txt" on mine branch:
    -mine.PNG
    while "text.txt" on master branch is as follows:
    -masterbranch.PNG
  2. Change the file on master branch as follows:

private void function1(){
	//something
}
public void function2(){
	//other things
}
  1. Send pull request from master to mine.
  2. Update mine branch, now conflict happens:
    conflict.JPG
  3. 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
}
  1. 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.

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?