Git-丢弃添加的文件 [英] Git - discard added files

查看:134
本文介绍了Git-丢弃添加的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来这样应该超级简单,但是到处寻找简单(或中途简单)的解决方案似乎是不可能的:

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

说我将一堆文件添加到Git项目中. 现在,"git status"显示为:

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?!!

我尝试过:

git checkout master  

给出已经在'master'上"和

which gives "Already on 'master'" and

git reset --hard HEAD

,但是我添加的文件仍然在这两种方法中.

but my added files are still there for both methods.

我已经阅读了整个Git教程( http: //www.kernel.org/pub/software/scm/git/docs/gittutorial.html )以及各种手册页.

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

为什么这么难做?!

推荐答案

git clean

应该可以解决问题.默认情况下,这需要-f标志真正执行任何操作.

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

这篇关于Git-丢弃添加的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆