简体   繁体   中英

Source tree - switching branch still contain the uncommited changes

Let say I have two branch - main and dev and I am currently in main branch
If I made some changes in certain files and save, then checkout to dev branch,
I find there still contains the changes I made in main branch.
Is it normal?
What should I do to avoid this situation?

That is normal ; those changes are both uncommitted and unstashed , which is to say that they exist purely on your filesystem (outside of Git). Also note that changes you make are not tied to a particular Git branch until they are committed.

If you find yourself in this situation, the most likely reason is that you wanted to stop working on one feature and start working on another one.

  • If you want to associate the changes with the previous branch that you were working on, simply commit those changes before swapping branches (you can always swap back to the old branch, commit, then swap to the new one if you forget). This will affix the changes to the branch, though it will still only be on your local branch (and invisible to other team members) unless you push to origin .
  • If you want to discard (but store those changes so you can come back to them later), simply stash the changes. Stashes mention they came from a particular branch, though a stash can be applied to any branch. This is useful if you accidentally started working on the wrong branch.

Both approaches will give you a clean copy of the new branch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM