Snowcrash
Snowcrash

Reputation: 86087

Git - discard added files

Seems like this should be super-simple but looking around for a simple (or half-way straightforward) solution seems impossible:

Say I add a bunch of files to a Git project. "git status" now says:

# On branch master  
# Untracked files:  
#   (use "git add <file>..." to include in what will be committed)  
#  
#   Classes/FileA.h  
#   Classes/FileA.m  
#   Classes/FileB.h  
#   Classes/FileB.m  
nothing added to commit but untracked files present (use "git add" to track)  

I then decide I want to discard these files and get back to my original status within the project. Do I have to delete each file before proceeding?!!

I've tried:

git checkout master  

which gives "Already on 'master'" and

git reset --hard HEAD

but my added files are still there for both methods.

I've been through the entire Git tutorial (http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html) plus various man pages.

Why is this so difficult to do?!!

Upvotes: 17

Views: 10683

Answers (2)

nekperu15739
nekperu15739

Reputation: 3698

I follow the git tip:

Changes to be committed: (use "git reset HEAD ..." to unstage)

new file:   src/main/java/com/bbva/zic/commons/rm/core/convert/support/BooleanToStringConverter.java
new file:   src/main/java/com/bbva/zic/commons/rm/core/convert/support/BooleanToStringConverterFactory.java
modified:   src/main/java/com/bbva/zic/commons/rm/core/convert/support/StringToDtoIntCollectionAgreementBillConcept.java

laura:bbva-commons charly$ git reset HEAD src/main/java/com/bbva/zic/commons/rm/core/convert/support/BooleanToStringConverter.java laura:bbva-commons charly$ git reset HEAD src/main/java/com/bbva/zic/commons/rm/core/convert/support/BooleanToStringConverterFactory.java laura:bbva-commons charly$ git status On branch INC0287 Changes to be committed: (use "git reset HEAD ..." to unstage)

modified:   src/main/java/com/bbva/zic/commons/rm/core/convert/support/StringToDtoIntCollectionAgreementBillConcept.java

Untracked files: (use "git add ..." to include in what will be committed)

src/main/java/com/bbva/zic/commons/rm/core/convert/support/BooleanToStringConverter.java
src/main/java/com/bbva/zic/commons/rm/core/convert/support/BooleanToStringConverterFactory.java

Upvotes: 0

Thomas
Thomas

Reputation: 181735

git clean

should do the trick. By default, this requires the -f flag to really do anything.

Upvotes: 14

Related Questions