Version management · Fun git (Branch Management)

In development, encountered such a situation how to do?
Website has Alipay online payment function, to add "micro-channel pay", modified two files, wechat.php, pay.php.
Just do half, suddenly have an urgent bug: can not modify the order status after Alipay. You'll need to modify this bug immediately, we need to modify the document is, ali.php, pay.php.
The problem is, pay.php file, you have been changed before, and not yet complete, change directly on this basis, have a problem. The pay.php go back? That my previous work in vain.
At this point you must be thinking: when do "micro-channel pay", the warehouse can copy, does not affect the contents of the original warehouse, after modification, and then modify the copy of the merger in the past.
Well, then you've got ideas branches.
It is seen in front of master, that is, the backbone of the branch code.
In fact, in the actual development, often do not directly modify and submit to the master branch, but to create a dev branch, on the dev branch, modify the test, then the dev branch into the master.
If you have a branch, just like the problem solved.
In doing "micro-channel pay", we create a wechat branch, the branch wechat commit, at this time, master branch content will not change, because of the different branches.
When an emergency bug, create a AliBug branch, after the restoration bug, the AliBug branch into the master branch.
Wechat calm again switched to the branch, and then developed "micro-payment letter" function, after the completion of the development, the wechat branch into the master branch.

Next, we explain in detail.
View all branches

git branch

Here Insert Picture Description
Thus only the master branch instructions, and the current in the master branch, in front of the star (*) in the current position.
Creating a branch

git brand wechat

Then we see the branch
Here Insert Picture Description
then have two branches, but we are still in the master branch.
Then we switch branches.

git checkout wechat

Here Insert Picture Description
Now we are on wechat the branch. Next, we make some modifications on wechat branch.
Here Insert Picture Description
Now config.txt file has been modified, but this time, there is an urgent need to bug you to deal with the master branch, then, you have to handle the work of the head of the saved, and then to deal with the bug.
We enter

git add .
git commit -m "wechat todo"

In this way, we'll save work carried out on the branch wechat in.
Next, we switch back to the master branch.

git checkout master

That's when the magic happened, look at your working directory, just increase the content I can not anymore. What we want is this effect, Next, we create a branch for repair bug.

git branch ali

Then switch to branch ali

git checkout ali

In this branch, we do something, create a file in the working directory, then feel free to write something.
Here Insert Picture Description
Assuming that we have repaired the bug, then we will commit the changes to the branch, the next step is the branch into the master branch.
Let's switch to the master branch, you will find the file we just created disappears in the working directory, and then we enter

git merge ali

This is a file on ali branch changes to the operation can be found in the working directory.
At this time, we can cut back wechat branch, did we just not done. When finished, we can also merge the piece of branch to master branch.

Deleted branches

git branch -d wechat

Attention, when we modify the same content on two branches, the time to merge in the master branch, will have a conflict, because the git can not determine which version you need is information.
Here Insert Picture Description
Within the meaning of the red border is to say, coding config.txt, conflict (content): Merge conflict in config.txt to automatically merge failed; fix a violation, and submit the results. We look at the file conflict.
Here Insert Picture Description
We look to resolve the conflict, if we are facing three values are necessary, we directly to the deleted mark on the line, which if not, do not need to put a value delete, and here I have to keep up.
Here Insert Picture Description
Modifications are complete, we will be able to resubmit it.

Guess you like

Origin www.cnblogs.com/blizzawang/p/11411724.html
Recommended