简体   繁体   English

git:分支?

[英]Git: branching?

I got a local script of which I want to have 2 version. 我有一个本地脚本,我想拥有2个版本。 So I went to the directory of the script and did this: 因此,我转到了脚本的目录并执行以下操作:

git init
git add myscript.py
git commit -m "initial"
git checkout -b test_branch

After that I opened the script in an editor and wrote "foobar" at the end of the file. 之后,我在编辑器中打开了脚本,并在文件末尾写了“ foobar”。 Then I went back to console and wrote: 然后我回到控制台并写道:

git checkout master

So basically I switched from my test_branch back to master. 所以基本上我从test_branch切换回master。 I opened the script and there was still the "foobar" at the end. 我打开了脚本,最后仍然有“ foobar”。 I was expecting it not to appear since I wrote it into the file when I was in the test_branch? 我期望它不会出现,因为我在test_branch时将其写入文件了吗?

After you checkout to test_branch and you do some changes there, then before you checkout your master branch, you first need to commit all the changes made to the test_branch . checkouttest_branch并在那里进行了一些更改之后,然后在checkout master分支之前,您首先需要提交对test_branch所做的所有更改。

So it would be like: 就像这样:

git init                      #initializing
git add myscript.py           #added a file, ready to commit
git commit -m "initial"       #initial commit made to master

git checkout -b test_branch   #created and checked out a new branch
git add myscript.py           #add a file, ready to commit to test_branch
git commit -m 'other version' #commit the changes made to test_branch
git checkout master           #checkout master again

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM