git checkout carries unstaged files to the new branch

后端 未结 3 606
感动是毒
感动是毒 2021-01-24 17:24

I have been trying to set-up repository with gitlab CE, as a part of the set-up created a repo and been playing around with it, when I encountered, that after I make some modifi

3条回答
  •  悲哀的现实
    2021-01-24 18:01

    Git won't change files that are not currently tracked in the repository. In your example, you only created an untracked file (newfile).

    So the Git's behavior is absolutely normal.

    If you git add newfile without commiting the changes, Git won't allow you to switch to master branch.

    For example, this will be handled by Git:

    $ git branch new-branch
    $ git checkout new-branch
    Switched to branch 'new-branch'
    $ echo "test" > newfile
    $ git add newfile
    $ git checkout master
    A       newfile
    Switched to branch 'master'
    

    For in depth explanations: https://stackoverflow.com/a/8526610/882697

提交回复
热议问题