I am trying to figure out the easiest way to switch back and forth between version of code to test while making changes. When I'm in the middle of something and want to test out something else I'll use git stash but that seems like overkill in this situation as it can't be done on individual files.
What I tried to do was git add {file}
to temporarily store changes and then git checkout {file}
to get back to the previous state. The intention being to have staging as a temporary holding area for a file and then pull the staged file back into my working directory. I was surprised though that after staging a file the checkout had no effect on the file in the working directory. Is there a series of command options that would allow this work flow to function as I want it to?
Update 1:
Based on docs it appears this would work if there was a way for step 2 to not overwrite the index
- git add {file}
- git checkout HEAD {file}
- git checkout {file}
Update 2:
After being inspired by ElpieKay's post to look at writing output of a command to file I found another answer that overcomes the limitation of step 2 above. With git show HEAD:{file} > {file}
I can now overwrite the working directory version of the file without overwriting index. Then calling checkout pulls the index version into the working directory. Combined with git checkout-index I get this...
- git add {file}
- git show HEAD:{file} > {file}
- git checkout-index -f