Outils pour utilisateurs

Outils du site


pele_mele:stack_exchange:stack_overflow:29131903

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:

  1. I move the file back to its original location
  2. I revert the chunks I don't want to include in the commit
  3. 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>
pele_mele/stack_exchange/stack_overflow/29131903.txt · Dernière modification : 2024/11/23 04:02 de alexis