Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I interactively unstage a particular hunk in git?

Tags:

git

staging

People also ask

How do I Unstage a specific file from a commit?

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.

Which command is used for interactive staging?

There is one variant of staging (add) and commit functions that is available to users: interactive staging. This command can help you craft your commits to include only certain combinations and/or parts of files. --interactive (or -i ) is the big brother of --patch .

What is the command to Unstage a staged file?

Using git restore to Unstage This will remove the file from the Staging Area, making sure that it will NOT be part of the next commit. This will discard any local modifications in this file and reset it to its last committed state.


Try git reset --patch filename; this should do the opposite of git add --patch, according to the documentation. The short form -p also works for both commands.


git gui has a decent GUI to interactively stage or unstage hunks or lines. There are prettier/better GUI clients, but git gui is lightweight, built-in, and cross platform (lin, win, mac).

https://git-scm.com/docs/git-gui

Simply right click on a hunk to stage/unstage. For lines, highlight the lines first, then right click.