官术网_书友最值得收藏!

Branches

We can make a new branch with git checkout -b, which will create the branch and switch to it automatically:

When we're in the branch, any code changes we make are associated with a branch, and when we leave the branch, they go away. This can be shown in the following example.

Let's say we want to change the moo cow to moo horse. For this, we'll run the following command to open up Emacs and edit the text file:

$ emacs file.txt

We'll then make the changes we want in the file:

We can then commit the file to the branch using the git commit -a command and add a commit message to keep track of the changes that we've made:

You'll see a record of those changes to show what's been committed:

You can then switch back to the master version using the git checkout master command to see the original files without any changes, and when we re-enter the branch, those changes come back:

This means that we can still work on bug fixes in our main branch while we are working on new features in their own development branches. For example, here we can enter the same text file and change the animal to a dog, leaving a comment explaining what we've done:

Then, when we commit that file, we'll also leave a message stating that we've just made a bugfix:

As always, we commit the file using the git commit -a command, and we are shown a record of the changes, as follows:

When we're finally happy with a feature, we can merge it into the main branch.

主站蜘蛛池模板: 墨竹工卡县| 稻城县| 咸宁市| 绵竹市| 铜山县| 博湖县| 揭阳市| 邳州市| 定西市| 洛阳市| 乳源| 墨竹工卡县| 伊通| 辰溪县| 松阳县| 田阳县| 绍兴市| 崇阳县| 哈密市| 中牟县| 青河县| 阳城县| 稻城县| 卓尼县| 松江区| 定西市| 壶关县| 密云县| 集安市| 兴化市| 宜春市| 柘城县| 怀集县| 民权县| 奉贤区| 呼图壁县| 焉耆| 永州市| 辰溪县| 商丘市| 怀宁县|