Git: branches should isolate the changes, or should not? -
i thought had decent grasp of git, i've been surprised. thought branches isolate changes other branches, started big experimental refactoring in new branch. refactoring, implied moving many files. when switched master still see changes though!
i went sandbox repository replicate problem:
$ git branch crazy-refactoring $ git checkout crazy-refactoring $ rm readme $ git checkout master $ git status # on branch master # changes not staged commit: # (use "git add/rm <file>..." update committed) # (use "git checkout -- <file>..." discard changes in working directory) # # deleted: readme # no changes added commit (use "git add" and/or "git commit -a") $ ls readme ls: cannot access readme: no such file or directory
why? whole point of me creating branch, try something, , throw away if unsuccessful. toughts?
you did not commit delete. committed changes "isolated".
regarding comment:
maybe i'm missing something, seems me weird , undesirable behavior.
think it:
you deleted readme
in crazy-refactoring
did not commit change. git knows changed file , did not commit it. in order preserve changes, not override them if checkout branch.
otherwise there no way git know changes have been when switch branch made changes in. lost, , far more worse seeing changes in other branch.
you current working directory current branch + uncommitted changes (unless reset them).
of course, git warn when checking out other branch, have uncommitted changes, desired keep changes and switch branch.
Comments
Post a Comment