2

I built a new file named test.txt in the master branch.
However,when I checkout into the test branch without commit it.
But I can also see it in the test branch

Why?

3
  • either u do git add or stash the changes Commented Nov 16, 2016 at 4:52
  • 2
    Untracked files are not under Git's management, so switching branches has no logical meaning for them. Commented Nov 16, 2016 at 4:54
  • In future, please include text output in your question instead of a screenshot to allow copy/pasting. Use the { } (code sample) button to format it nicely. Commented Nov 16, 2016 at 4:59

2 Answers 2

2

Untracked files are left as they are when switching branches. To make test.txt part of the master branch (so that when you checkout the test branch it disappears), you need to add it using git add test.txt and commit using git commit.

If the untracked files were removed when you switched branches, they would be gone forever because they aren't committed. Git tries pretty hard to prevent that from happening.

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

2 Comments

solve it.thank you.I was use windows which reject my checkout branch when the changes hadn't commited.so It troubled me when I use mac.
@dredh, you may mark it as an answer if it helped you )
1

when you run git status in master branch, it shows test.txt is a "untracked file", that means test.txt is not under management of git, then what do you expect git do for you?

1 Comment

I was use windows which reject my checkout branch when the changes hadn't commited.so It troubled me when I use mac

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.