2
When I use the remote git stash
to hide the changes, sometimes you need to change that same file, while it is already hidden by Stash.
When I try to apply one git stash pop
, but at the same time one of the files that is saved by stash has a modification in the current branch, an error message appears, informing about this modification.
I made a small code as an example below
Example:
>> mkdir test_repo
>> cd test_repo
>> git init
>> echo "Arquivo A" > a.txt
>> git add a.txt
>>git commit -m "Criando o arquivo A"
>> echo "Arquivo A modificado para fazer um teste com Stash" > a.txt
git stash
>> echo "Arquivo A modificado mais uma vez" > a.txt
>> git stash pop
When I do this, the following error is issued:
error: Local changes of the following files will be overwritten during merge: a.txt.
Confirm your changes or wait for them before merging. Aborting
Is there any way to force git stash pop
overwrites the file in the current job, whether or not it has modifications?
Have you tried
git stash apply
?– Felipe Avelar
If you want to actually overwrite the files, you could use the
git checkout stash -- .
, No? What would your branch files in the current directory look like in the stash version...– Felipe Avelar
@Felipeavelar this second option works, the first failed to try.
– Wallace Maxters