3

I have a master branch to where I had commited my last change and then after I ran

git branch test
git checkout test

I deleted file README in the project folder

then I ran

git checkout master

Now there is no README file anymore.

I thought that when you create a new branch it's just like creating a new commit. What am I doing wrong?

6
  • Did you actually commit in the test branch? Because if you didn't your changes would just have been lost when you went back to the master branch. Commented Sep 13, 2012 at 22:52
  • No i did not commit on test, changes was to delete README when i went back to master README was still not there. Commented Sep 13, 2012 at 22:53
  • checkout test means you never changed branch. git checkout test? Commented Sep 13, 2012 at 22:55
  • yes git checkout test... Commented Sep 13, 2012 at 22:56
  • elcanibal - changes not lost by switching to different branch before commiting, test it. Commented Sep 13, 2012 at 22:58

1 Answer 1

4

Creating a branch is not like creating a new commit. Creating a branch is like creating an easy to read reference to a commit hash.

So by being on the master branch and then going:

git branch test
git checkout test
rm README
git checkout master

You will still have unstaged changes on the master branch, because you didn't actually do anything to test.

If you do git status you should have README missing.

You can get it back by doing git checkout README.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.