Reputation: 1109
I got a local script of which I want to have 2 version. 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. Then I went back to console and wrote:
git checkout master
So basically I switched from my test_branch back to master. I opened the script and there was still the "foobar" at the end. I was expecting it not to appear since I wrote it into the file when I was in the test_branch?
Upvotes: 0
Views: 39
Reputation: 157414
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
.
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
Upvotes: 3