Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unstage only new files using Git [duplicate]

Tags:

git

I've accidentally staged a lot of changes including new files that I do not want to commit.

How can I unstage or reset only the new files?

I am not looking for a script of any kind; I am looking for core git functionality to be exposed and documented here on SO under a meaningful topic title.

like image 935
ThorSummoner Avatar asked Jun 24 '14 19:06

ThorSummoner


People also ask

How to unstage a file in Git?

The cached command helps to unstage new files, i.e., files not committed. 2. The restore command is crucial in unstaging modified files, i.e., files already committed. 3. Git reset mixed You can use the reset command in four ways when unstaging a file. to git unstage files before committing them. git reset . to unstage modified files.

How do I unstage all files in a staging area?

To unstage all files, use the “git reset” command without specifying any files or paths. Again, let’s pretend that you have created two files and one directory and that you added them to your staging area. $ git status On branch master Your branch is up to date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..."

How to undo changes in Git?

Git reset is one of the most crucial commands when undoing changes. The three types of reset command are hard, soft, and mixed. Git reset hard removes changes from the commit history and deletes the files from the working directory. Git reset soft resets the commit HEAD, while git reset mixed unstages files.

What happens when you hard reset a Git file?

A hard reset has the following effects: If no option is specified, the git reset command performs a mixed unstage: Note: Hard resets are used frequently, but can cause lost work if used carelessly. You should now have a solid understanding of how to unstage files in Git.


1 Answers

One way you may be able to do this is to unstage / reset everything and then re-stage only what you wanted:

git reset HEAD ./
git add -u
# -u stages changes to tracked files, and will not stage new files.
like image 154
ThorSummoner Avatar answered Oct 12 '22 14:10

ThorSummoner