Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Unstage and Discard in a single command in git

Tags:

In git,
to unstage a file git reset HEAD <filename> is used
to discard changes git checkout <filename> is used

Is there a way to combine these two commands in one?

like image 954
Dimitris Baltas Avatar asked Nov 19 '10 13:11

Dimitris Baltas


People also ask

How do I Unstage a file in git command line?

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.

How do I remove changes to a specific file in git?

Try Git checkout --<file> to discard uncommitted changes to a file. Git reset --hard is for when you want to discard all uncommitted changes. Use Git reset --hard <commit id> to point the repo to a previous commit.

How do I get rid of Unstage changes?

For all unstaged files in current working directory use: git restore . That together with git switch replaces the overloaded git checkout (see here), and thus removes the argument disambiguation. If a file has both staged and unstaged changes, only the unstaged changes shown in git diff are reverted.

How do I undo a git restore stage?

Remove New Files from Staged Files Staged files are those which go into your next commit. If you accidentally added files to the staged area, you can undo this by typing git restore --staged <file> , so in this case, it would be git restore --staged lib.


1 Answers

Try

git checkout HEAD <filename>
like image 79
Sven Marnach Avatar answered Sep 20 '22 15:09

Sven Marnach