The clean way to make a branch in Git a posteriori
Say you are working on a branch, and you come up with an interesting behavior you want to archive as an开发者_开发技巧 experimental branch. What is the cleanest way to do this?
Cleanest way I can think of off the top of my head:
1) Backup your local version to another directory.
2) git checkout, to revert back to your last commit
3) git branch experiment_name, make the new branch
4) git checkout experiment_name, switch to the new branch
5) Copy your backed up version to the working git directory.
6) git commit, commit your new fancy experimental branch
If you don't have a clean index:
git stash
git checkout -b name
git stash pop
... more edits
git commit
If you have a clean index, you can just create a new branch off the current head:
git checkout -b name
... edits
git commit
Or if you have edits that belong to the current branch and you want to work on a new experimental branch for some time and return then:
git stash
git checkout -b name
... edits
git commit
git branch master
git stash pop
... continue work
Just git checkout -b experiment_name
and commit.
For very temporary things, perhaps git stash
.
精彩评论