Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the fastest way to unstage parts of a new file in git?

Tags:

When I want to split up a new file into several commits I can git add -N <file> and then interactively stage lines using git gui. When I make a mistake while staging, however, git gui won't let me unstage individual lines because it is a new file (which seems like a bug to me). Of course I can always unstage the whole file and start over again, but I am wondering whether there is a more efficient way to do so.

I am using git 1.7.5.


To clarify, this question is specific to new aka untracked files!

like image 486
Tobias Avatar asked Jul 26 '11 09:07

Tobias


People also ask

How do you Unstage a file in git?

To unstage commits on Git, use the “git reset” command with the “–soft” option and specify the commit hash. Alternatively, if you want to unstage your last commit, you can the “HEAD” notation in order to revert it easily. Using the “–soft” argument, changes are kept in your working directory and index.

What does Unstage all changes do?

Unstage All Files on Git This will remove all changes from the staging area. It will not delete any files – the git add command can be used to re-add changes back into the staging index. The staging index is located at .

Which command Unstage the file but it preserve the file content?

Usage: git reset [file] This command unstages the file, but it preserves the file contents.


1 Answers

From the command line type:

git reset -p 

This will let you selectivelty unstage hunks from the index using the standard command-line interface for managing hunks.. This is the opposite of git add -p.

UPDATE

OK, it would appear that you cannot selectively stage different hunks when the file is new. Given that git-gui and the standard git hunk editor both do not allow this, it probably isn't possible.

like image 146
Mike Weller Avatar answered Sep 21 '22 19:09

Mike Weller