git: commit state of current code to new branch without affecting current branch -


i'm looking way automatically save current state of code whenever run experiment.

but not want pollute commit history of main branch million automatically-made commits. thinking of making my_experiments branch, push current state of code whenever experiment runs.

so guess want commit current code experiments branch, without committing current branch. still want retain uncommitted code on current branch.

what nicest way in git?

edit

i've been asked clarify want , why.

sometimes make change code in order test something. changes typically ugly hacks. typically process goes:

  • make hacky change
  • run code , save result
  • ctrl-z
  • view saved result

i saving results of run, , save state of code alongside it.

now want these "hack" changes separate normal development cycle - need record of state of code when made hack. rather have series of "make hack" "revert-hack" pairs in commit history of main branch, i'd have "hacky" changes committed single "experiments" branch.

there nothing wrong making large number of commits on branch, because can squash them down @ later point, assuming have not yet pushed them. example, assuming made 10 small commits on branch, wanted push single logical commit, use reset soft:

git reset --soft head~10 git commit -m 'single commit changes' git push origin master 

if want take snapshot of branch in current state, create new branch head, e.g.

git branch backup_experiment_1 

although typically don't need because git flexible single branch.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -