Who faced such a git problem, after checkout, all changes remain as in the branch with which it went. Does git status show the same thing?

    1 answer 1

    It's not a problem. It should be so.

    Index one for the entire repository. For all branches of the repository, it is one.

    And Git tries not to lose the changes. Never. And if during the transition between branches changes in the index (made by git add or in other ways) conflict with the changes "between branches", Git refuses to do checkout , citing the fact that he will have to rewrite some of the changes (he even lists which ones); offering to commit them instead or put them in a stash .

    And if there is no conflict, it will quietly switch the working tree to another branch, without changing the index state in any way. What is happening with you?

    This is especially convenient when the developer made changes, and right before the commit (having done all the git add ), he realized that he made the wrong branch (say, he accidentally made a master , but he wanted to dev ). In the simplest case, the case will be limited to two commands: git checkout dev and git commit .

    If you still want to reset the index, losing the changes in it , do a git reset .

    If you want to postpone the changes "for later", make git stash -k ( k : "Keep index"), and in the right place git stash pop .