How to revert a chunk of a file in the staging area?
I have a file in my staging area and I want to unstage a chunk of it. I know I can use the following command:
git reset --patch -- <my_file>
But in my case, the name file was renamed and every time I am trying to validate the reset, I have the following error:
fatal: new file my_file depends on old contents
Is there a way to do what I need? Or I am screwed?
Edit:
I read the following documentation before posting this question:
Edit:
Git status output:
Changes to be committed: (use "git reset HEAD <file>..." to unstage) renamed: src/MyBundle/Config.php -> src/MyBundle/QueryConfig/Config.php
In the rename process, I want to keep some changes (namespace change) but I want to discard other changes (not related to namespace change) to commit them later.
So finally I found a process that works for me:
- I move the file back to its original location
- I revert the chunks I don't want to include in the commit
- I move the file to its final location
So here are the commands :
git mv <final_path>/<file> <original_path>/<file> git reset -p <original_path>/<file> git mv <original_path>/<file> <final_path>/<file>
@MatzZze Even if I did not use your solution, I thank you for your help. It is greatly appreciated.
To unstage chunks use:
git reset HEAD -p <filename>
After that you can reset your changes with
git checkout -p <path to file>