How do I segregate my changes in git branches when I'm not ready to commit?

StackOverflow https://stackoverflow.com/questions/23075704

  •  03-07-2023
  •  | 
  •  

質問

So, I have two git branches, master and testing. I checkout testing. I make some changes that are only halfway done and not ready to even stage let alone commit, I'm just screwing around. If I checkout master again, my screwy changes are included!! What??

So I could accidentally have some bad stuff in master just because it was not good enough to even commit in testing?

I thought branches would segregate my work. I tried staging even and that didn't seem to work. It seemed like I have to actually commit in testing or else my changes will stay visible (but uncommitted) in the files in my master branch.

What am I missing?

役に立ちましたか?

解決

That's what git-stash is for. You can stash your changes using

git stash

and get them back using

git stash apply

when you are done you should clear your stash using

git stash clear

If you want to just delete your changes you can use

git reset --hard
git clean -fd

Info taken from here.

他のヒント

You could simply make a "tmp" branch, and commit in it.

git checkout -b tmp

That way, master, and testing are unchanged.
And you can resume your changes in tmp at any time.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top