Git porcelain team to return a single file to HEAD state, but keep it phased in?

Is there a git china command to return the working state of the dir of the staged file to the HEAD state and at the same time to save the staged state of the file? Later, I would like to be able to return the working state of dir to the phased state of the file. My initial thought was to use the git checkout HEAD -- targetfile , but it also resets the phased state of the file. I see that this is possible with git stash , but it affects the other files, while I would like to focus on one file and keep the state of the others untouched, otherwise it could lead to merge conflicts:

 git add targetfile git stash ... // modify tagetfile in seeking of different task solution, possibly modifying other files too git checkout HEAD -- targetfile //drop the different solution attempt, keep other modified files if any git stash apply --index // revert to the stashed staged solution, but produces merge conflict for other modified files 

I found a good article with a summary table at the end that lacks the script described in this question. In my opinion, this should be easily feasible, but I am surprised that the set and working dir-states are so closely related - you can reset the phased state of the file, while maintaining its working state, but it is difficult for me to find the other way around.

+4
source share
1 answer

This is not very pleasant, since it will not receive the correct executable state of the file, but when pressed, you can do:

 git show HEAD:targetfile > targetfile 

Ideally for git checkout HEAD -- targetfile you need to have the --working-tree-only option, but I don't know anything about that.

+3
source

All Articles