Outils pour utilisateurs

Outils du site


pele_mele:stack_exchange:stack_overflow:29131903

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
pele_mele:stack_exchange:stack_overflow:29131903 [2024/11/23 04:02] – supprimée - modification externe (Date inconnue) 127.0.0.1pele_mele:stack_exchange:stack_overflow:29131903 [2024/11/23 04:02] (Version actuelle) – ↷ Nom de la page changé de pele_mele:stack_exchange:stack_overflow:stackoverflow-29131903 à pele_mele:stack_exchange:stack_overflow:29131903 alexis
Ligne 1: Ligne 1:
 +====== 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:
 +
 +<code>
 +git reset --patch -- <my_file>
 +</code>
 +
 +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:
 +
 +  * [[https://stackoverflow.com/questions/23295986/undo-local-changes-interactive/23296148#23296148|Undo local changes interactive]]
 +  * [[http://git-scm.com/book/en/v2/Git-Tools-Interactive-Staging|http://git-scm.com/book/en/v2/Git-Tools-Interactive-Staging]]
 +  * [[http://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified|http://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified]]
 +
 +**Edit**:
 +
 +Git status output:
 +
 +<code>
 +Changes to be committed:
 +  (use "git reset HEAD <file>..." to unstage)
 +
 +        renamed:    src/MyBundle/Config.php -> src/MyBundle/QueryConfig/Config.php
 +</code>
 +
 +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.
 +
 +<WRAP help>
 +
 +
 +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 :
 +
 +<code>
 +git mv <final_path>/<file> <original_path>/<file>
 +git reset -p <original_path>/<file>
 +git mv <original_path>/<file> <final_path>/<file>
 +</code>
 +@MatzZze Even if I did not use your solution, I thank you for your help. It is greatly appreciated.
 +</WRAP>
 +<WRAP help>
 +To unstage chunks use:
 +<code>
 +git reset HEAD -p <filename>
 +</code>
 +After that you can reset your changes with
 +<code>
 +git checkout -p <path to file>
 +</code>
 +</WRAP>
 +<WRAP info>
 +[[https://stackoverflow.com/questions/29131903/how-to-revert-a-chunk-of-a-file-in-the-staging-area|git - How to revert a chunk of a file in the staging area? - Stack Overflow]]
 +</WRAP>