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!
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.
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 .
Usage: git reset [file] This command unstages the file, but it preserves the file contents.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With