Git acts differently when checking for other branches until the working directory is cleared

After creating a new repository using git initand performing the first commit (in the branch master)

Then I tried to edit some files while working directory has not yet been cleared, I could do git checkout -b dev , and then git add ., git commit(in the dev branch) all successfully.

But at this time, after editing the files in the dev branch, while the working directory has not yet been emptied, I can’t do it git checkout master , git asks me to sew up or otherwise complete the commit before moving on to other branches.

I am so curious why git acts differently in this case.

Edit (add screenshot)

+4
source share
1

, , .
git checkout -b .

, master, dev HEAD, , .

, ( , ), , .
master, dev , git stash git commit.


git checkout man :

, , , , , .

git checkout , .

OP git checkout -b dev master, dev ( dev ).

git checkout master file1 dev ( ), file1 master: a git stash commit .

+2

Source: https://habr.com/ru/post/1598489/


All Articles