博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
暂存已删除的文件
阅读量:2381 次
发布时间:2019-05-10

本文共 2164 字,大约阅读时间需要 7 分钟。

本文翻译自:

Say I have a file in my git repository called foo . 假设我的git储存库中有一个名为foo的文件。

Suppose it has been deleted with rm (not git rm ). 假设已使用rm (不是git rm )将其删除。 Then git status will show: 然后git status将显示:

Changes not staged for commit:    deleted: foo

How do I stage this individual file deletion? 如何分阶段删除单个文件?

If I try: 如果我尝试:

git add foo

It says: 它说:

'foo' did not match any files.

#1楼

参考:


#2楼

Use git rm foo to stage the file for deletion. 使用git rm foo要删除的文件。 (This will also delete the file from the file system, if it hadn't been previously deleted. It can, of course, be restored from git, since it was previously checked in.) (如果以前没有将其删除,这也会从文件系统中删除该文件。由于先前已将其检入,因此当然可以从git中还原它。)

To stage the file for deletion without deleting it from the file system, use git rm --cached foo git rm --cached foo要删除的文件而不将其从文件系统中删除,请使用git rm --cached foo


#3楼

Even though it's correct to use git rm [FILE] , alternatively, you could do git add -u . 即使使用git rm [FILE]是正确的,也可以执行git add -u

According to the git-add documentation: 根据git-add文档:

-u --update -u-更新

Update the index just where it already has an entry matching . 在索引中已有条目匹配的地方更新索引。 This removes as well as modifies index entries to match the working tree, but adds no new files. 这会删除和修改索引条目以匹配工作树,但不会添加任何新文件。

If no is given when -u option is used, all tracked files in the entire working tree are updated (old versions of Git used to limit the update to the current directory and its subdirectories). 如果在使用-u选项时未指定任何值,则将更新整个工作树中的所有跟踪文件(旧版本的Git用于将更新限制为当前目录及其子目录)。

Upon which the index will be refreshed and files will be properly staged. 索引将在此刷新,文件将被适当地暂存。


#4楼

You can use 您可以使用

git rm -r --cached -- "path/to/directory"

to stage a deleted directory. 暂存已删除的目录。


#5楼

to Add all ready deleted files 添加所有准备好的已删除文件

git status -s | grep -E '^ D' | cut -d ' ' -f3 | xargs git add --all

thank check to make sure 感谢检查以确保

git status

you should be good to go 你应该很好去


#6楼

To stage all manually deleted files you can use: 要暂存所有手动删除的文件,可以使用:

git rm $(git ls-files --deleted)

To add an alias to this command as git rm-deleted , run: 要将别名添加为git rm-deleted ,请运行:

git config --global alias.rm-deleted '!git rm $(git ls-files --deleted)'

转载地址:http://syexb.baihongyu.com/

你可能感兴趣的文章
Intel比AMD高明在哪里?
查看>>
HDF文件的显示策略
查看>>
有点坑爹的GDALComputeRasterMinMax函数
查看>>
应用网络电视机顶盒通过宽带网络代替数字电视
查看>>
一次使用OCI的排错经历
查看>>
geotif格式的波段描述信息探究
查看>>
如何让hudson的两个job共用一个svn工作目录
查看>>
调用C#版gdal库的一个注意事项
查看>>
你可能不知道Windows系统下有一个UNIX子系统
查看>>
有关R6034错误的思考
查看>>
一部描写真实人性的小说
查看>>
你会做年度计划吗?
查看>>
VS 2005中毒后编译出现的错误及其解决过程
查看>>
周国平:教育的七条箴言
查看>>
应用程序初始化失败问题的解决
查看>>
开启Windows 7远程桌面功能的做法
查看>>
有关error PRJ0003错误的思考
查看>>
韩少功:怎么赚钱
查看>>
如何煮鸡粥
查看>>
实现自定义对话框程序快捷键的两种方法
查看>>