如何不将本地删除的文件提交到git [英] How to NOT commit locally deleted files to git

查看:371
本文介绍了如何不将本地删除的文件提交到git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们遇到一种情况,正在使用git来存储大量扫描(图像),并且不希望在设置好之后将其保存在本地计算机上;但是,git将每个本地删除(遵循此过程)视为要提交给存储库的某种东西,我们希望这种情况不会发生.关于如何仅提交其他文件而不删除任何内容的任何想法?

We have a situation where were are using git to stash myriad scans (images) and do not wish to preserve them on the local machine once set on up; however, git is seeing each local deletion (following this process) as something to be committed up to the repo, and we want that not to happen. Any ideas on how to commit only the additional files and never any deletions?

推荐答案

使用跳过工作树"位

git-update-index(1 )命令提供了一些解决方法.基于您要在将斑点从工作树中删除时将其保留在历史记录中的假设,您可以使用以下代码:

Use the Skip-Worktree Bit

The git-update-index(1) command provides some ways of dealing with this. Based on the assumption that you want to keep the blobs in your history while deleting them from your working tree, you could use the following:

git add --all
git commit --message="Add new assets to repository."
git update-index update-index --skip-worktree <files ...>
rm <files ...>

请注意,最后一行不是Git命令,因为您是在将文件存储在索引中之后从外壳中的工作树 中删除文件的.请勿误用git rm,因为它在索引上起作用.

Note that the last line isn't a Git command because you're removing the files from the working tree in the shell after you've stored them in the index. Don't use git rm by mistake, because it operates on the index.

要查看已用skip-worktree位标记的文件,请执行以下操作:

To see the files you've marked with the skip-worktree bit:

git ls-files -v | awk -v IGNORECASE=1 '$1 ~ /s/ {print}'

您还可以使用 git-ls- files(1),以查找索引中已从工作树中删除的文件.

You can also use git-ls-files(1) to find files in the index that have been removed from your working tree.

这篇关于如何不将本地删除的文件提交到git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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