pele_mele:stack_exchange:stack_overflow:29131903
Différences
Ci-dessous, les différences entre deux révisions de la page.
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.1 | pele_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: | ||
+ | |||
+ | < | ||
+ | git reset --patch -- < | ||
+ | </ | ||
+ | |||
+ | 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:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | |||
+ | **Edit**: | ||
+ | |||
+ | Git status output: | ||
+ | |||
+ | < | ||
+ | Changes to be committed: | ||
+ | (use "git reset HEAD < | ||
+ | |||
+ | renamed: | ||
+ | </ | ||
+ | |||
+ | 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 : | ||
+ | |||
+ | < | ||
+ | git mv < | ||
+ | git reset -p < | ||
+ | git mv < | ||
+ | </ | ||
+ | @MatzZze Even if I did not use your solution, I thank you for your help. It is greatly appreciated. | ||
+ | </ | ||
+ | <WRAP help> | ||
+ | To unstage chunks use: | ||
+ | < | ||
+ | git reset HEAD -p < | ||
+ | </ | ||
+ | After that you can reset your changes with | ||
+ | < | ||
+ | git checkout -p <path to file> | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP info> | ||
+ | [[https:// | ||
+ | </ | ||