-2

I have 3 branches in a project that should've been all discretely separate from the beginning, but alas, I'm still learning git and they got muddled together about halfway through my work.

Currently I can switch between master and my dev-1 branches. In doing so, I get a display of

M this/is/a/file.path M this/is/also/a/file.path M this/is/a/file.path

and I cannot switch two my dev-2 branch without committing or stashing changes, which I don't think I want to do yet.

I would first like to know what the output above actually means. I've found examples that say those files have been modified, which is true, but why do I not have to stash or commit them before switching between master and dev-1?

Furthermore, I'd like my master branch to be completely clean and only have changes on my dev-1 and dev-2 branches, but I am not sure the best ways to accomplish this, as my master and dev-1 branches seem to share information.

CDorr
  • 17
  • 1
  • See http://stackoverflow.com/questions/22053757/git-checkout-another-branch-when-there-are-uncommitted-changes-on-the-current – torek Feb 16 '17 at 00:58
  • You're asking three questions. Consider breaking them out into three separate SO questions. – Shaun Luttin Feb 16 '17 at 01:29

1 Answers1

0

For the display you got, left-hand column M (2cd and 3rd records) means changes of the file has added in staging area (changes to be committed), right-hand column M (1st record) means changes has not staged (changes not staged for commit).

When you want switch to another branch while there have changes not commit or stashing, git will protect the changes and stop switch to another branch. If you really don’t the changes, you can force switch to another branch by git checkout -f branchname. This will cause you can’t find these changes in history since you are not committed them.

Completely clean branch (with no commits on it) is not exist. If you don’t want some latest changes you committed on master branch, you can reset by git reset --hard HEAD~n, the n is the latest commits count which you want to remove.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74