git rm undo对于未添加的文件 [英] git rm undo for the files that are not added

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

问题描述

我是git的新手,犯了一个大错误.其他相关线程无法解决我的问题.这就是发生的事情,感觉像"git rm"像linux rm命令一样工作.

I am newbie to git and I committed a big mistake. Other related thread didn't solve my problem. Here is what happened, it feels like "git rm" worked like linux rm command.

在一开始,我使用

git add dir_name1

在过去的几天里,我在该目录中创建了几个文件并重命名了一些文件,我认为这需要在git中手动添加新文件,因为在此之后我要进行所有更改,但是新文件未保存在回购中.

During last couple of days I created few more files in that directory and renamed a few, I think it requires manually adding new files in git, as I was committing all kind of changes after that but new files didnt save in repo.

今天完成工作后,我决定使用来添加这些新文件

Today after finishing the work, I decided to add those new files using

git add dir_name1

我猜会自动找到并添加新文件,但是当我看到一些临时文件(在ubuntu中以〜"结尾的文件)也添加了.

I guess with that new files will be found and added automatically, but when I saw that some temporary files (file ending with "~" in ubuntu) were also added.

为了删除那些tmp文件,我认为"git rm"是"git add"的对应物,因此我可以先执行"git rm dir_name1",然后手动删除所有以〜结尾的文件,然后执行"git add dir_name1"",那么就可以了.

In order to remove those tmp files I thought that "git rm" is the counterpart of "git add" so I could do "git rm dir_name1" followed by delete all files ending with ~ manually, and do "git add dir_name1" again then it will be ok.

所以我做的是

git rm -r -f  dir_name1

天哪,缺少整个目录,使用"git reset"恢复,其他一些技巧也没有恢复这些新文件.

My God, the entire directory is missing,restoring with "git reset" and few other tricks didnt restore those new files.

"git rm"是否像linux"rm"命令一样被删除?有没有办法恢复这些文件.

Does "git rm" removes just like linux "rm" command? is there a way to recover those files.

SOSSSSS

推荐答案

我看到还添加了一些临时文件(在ubuntu中以〜"结尾的文件)

I saw that some temporary files (file ending with "~" in ubuntu) were also added

.gitignore 中的简单 *〜可以阻止

我可以先执行"git rm dir_name1",然后手动删除所有以〜结尾的文件

I could do "git rm dir_name1" followed by delete all files ending with ~ manually

git rm -r -f dir_name1 (或 rm -r -f dir_name1 )将从磁盘上删除文件夹及其内容,无论是否包含git .

git rm -r -f dir_name1 (or rm -r -f dir_name1) will remove the folder and its content from the disk, with or without git.

您可能仍然可以通过以下方式跟踪以前添加(暂存)的文件:

You might still have a trace of those previously added (staged) files with:

git fsck --cache --unreachable $(git for-each-ref --format="%(objectname)")

更多信息,请参见"使用暂存区域中未提交的文件撤消 git reset --hard "

Read more in "Undo git reset --hard with uncommitted files in the staging area"

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

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