Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git checkout does not change anything

I really like git. At least, I like the idea of git. Being able to checkout my master project as a separate branch where I can change whatever I want without risk of screwing everything else up is awesome. But it's not working.

Basically, my workflow is like this:

  1. Checkout stable version to a new branch to experiment with new code
  2. Make a bunch of changes - I have no intent on keeping any of this, I'm just experimenting.
  3. Look at all the stuff I changed
  4. Add all the changes to be tracked
  5. Commit the branch and push branch to origin (if it worked, otherwise skip this step)
  6. Decide to try another method, go back to master
  7. Observe artifacts from the experimental branch I was working in, even though I'm in the master branch.

Every time I checkout a branch to another branch, make changes to the one branch, and then checkout the original branch, I still have all the files and changes that happened in the other branch. This is getting extremely frustrating. I've read that this can happen when you have files open in the IDE while doing this, but I've been pretty careful about that and both closed the files in the IDE, closed the IDE, and shut down my rails server before switching branches, and this still happens. Also, running 'git clean -f' either deletes everything that happened after some arbitrary commit (and randomly, at that), or, as in the latest case, didn't change anything back to its original state.

I thought I was using git correctly, but at this point, I'm at my wit's end here. I'm trying to work with a bunch of experimental code using a stable version of my project, but I keep having to manually track down and fix all the changes I made. Any ideas or suggestions?

git checkout -b photo_tagging git branch # to make sure it's right # make a bunch of changes, creations, etc git status # see what's changed since before git add . # approve of the changes, I guess, since if I do git commit after this, it says no changes git commit -m 'these are changes I made'  git checkout master git branch #=> *master  # look at files, tags_controller is still there, added in photo_tagging # and code added in photo_tagging branch are still there in *master 

This seems to happen whether I do a commit or not on the branch.

like image 326
Josh Kovach Avatar asked Dec 23 '10 03:12

Josh Kovach


People also ask

Does git checkout make changes?

Simply making changes to the working copy with a given branch checked out doesn't preserve them in any way. If your working tree is clean (that is, it has no uncommitted changes), git checkout will completely change the state of your working tree to another branch.

How do I force git checkout?

Force a Checkout You can pass the -f or --force option with the git checkout command to force Git to switch branches, even if you have un-staged changes (in other words, the index of the working tree differs from HEAD ). Basically, it can be used to throw away local changes.

What does git checkout do?

The git checkout command lets you navigate between the branches created by git branch . Checking out a branch updates the files in the working directory to match the version stored in that branch, and it tells Git to record all new commits on that branch.

How do I checkout and ignore changes?

you can do git checkout -m <branch-name> to merge conflicts and checkout to the branch and resolve conflicts yourself, or git checkout -f <branch-name> to ignore changes.


1 Answers

I had this issue when I tried to switch temp to another branch from the master branch and when I would change something on that temp page and without committing the changes I would checkout the master branch again, it actually merged all the changes from the TEMP branch into MASTER.

ANSWER:

Whenever you checkout to a TEMP branch, COMMIT your changes. That way if you commit them on the TEMP branch and checkout MASTER again, it will work as supposed.

like image 91
shabany Avatar answered Sep 19 '22 11:09

shabany