如何从git临时区域删除文件?

本文翻译自:How to remove files from git staging area?

I made changes to some of my files in my local repo, and then I did git add -A which I think added too many files to the staging area. 我对本地存储库中的某些文件进行了更改,然后我进行了git add -A ,我认为这会在过渡区域中添加了太多文件。 How can I delete all the files from the staging area? 如何从暂存区删除所有文件?

After I do that, I'll just manually do git add "filename" . 完成之后,我将手动执行git add "filename"


#1楼

参考:https://stackoom.com/question/1Kmov/如何从git临时区域删除文件


#2楼

You can unstage files from the index using 您可以使用以下命令从索引中取消暂存文件

git reset HEAD -- path/to/file

Just like git add , you can unstage files recursively by directory and so forth, so to unstage everything at once, run this from the root directory of your repository: 就像git add ,您可以按目录递归取消文件等,因此要一次取消所有文件的运行,请从存储库的根目录运行此文件:

git reset HEAD -- .

Also, for future reference, the output of git status will tell you the commands you need to run to move files from one state to another. 另外,为了将来参考, git status的输出将告诉您将文件从一种状态转移到另一种状态所需的命令。


#3楼

If you've already committed a bunch of unwanted files, you can unstage them and tell git to mark them as deleted (without actually deleting them) with 如果您已经提交了许多不需要的文件,则可以取消暂存它们, 告诉git将它们标记为已删除(实际上并没有删除它们),

git rm --cached -r .

--cached tells it to remove the paths from staging and the index without removing the files themselves and -r operates on directories recursively. --cached告诉它从暂存和索引中删除路径,而不删除文件本身, -r递归地处理目录。 You can then git add any files that you want to keep tracking. 然后,您可以git add要跟踪的任何文件。


#4楼

You could use 你可以用

git reset HEAD

then add the specific files you want with 然后添加所需的特定文件

git add [directory/]filename

#5楼

Use 采用

git reset

to unstage all the staged files. 取消所有已暂存的文件。


#6楼

As noted in other answers, you should use git reset . 如其他答案所述,您应该使用git reset This will undo the action of the git add -A . 这将撤消git add -A

Note: git reset is equivalent to git reset --mixed which does this 注意: git reset等同于git reset --mixed

Resets the index but not the working tree (ie, the changed files are preserved but not marked for commit) and reports what has not been updated. 重置索引,但不重置工作树(即,已更改的文件将保留,但未标记为提交),并报告尚未更新的内容。 This is the default action. 这是默认操作。 [ git reset ] [ git reset ]

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值