How does he decide
A quick experiment shows the following.
Suppose you are on the dev branch and you have changed foo.txt . Without commit you are trying to check master . There will be one of two things.
If foo.txt been changed in master to a commit that dev does not have, you are not allowed to switch without committing, because master has a "new" version of the file that conflicts with unspecified changes.
To “check” master , so Git would need to upgrade foo.txt to a newer version that master has, destroying your unspecified changes. To prevent your losing work, it will not change branches.
- Otherwise, the modification has been made “since the
master version knows about it, and you can change the branches. Git does not need to update the file because master does not have new information about the file.
For changes "exclamations"
Due to the foregoing, if you have unidentified changes to files on one branch and you really want to commit the changes to another, you may or may not be able to check another branch.
You can, however, do the following:
git stash save "here a summary of my changes" (a summary will appear on the git stash list )git checkout otherbranchgit stash pop (which is a combination of git stash apply and git stash drop )
Nathan Long Dec 15 2018-11-21T00: 00-11
source share