撤消 git update-index --assume-unchanged <file>

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17195861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:24:16  来源:igfitidea点击:

Undo git update-index --assume-unchanged <file>

gitversion-controlgit-index

提问by adardesign

The way you Git ignore watching/tracking a particular dir/file. you just run this:

Git 忽略监视/跟踪特定目录/文件的方式。你只需运行这个:

git update-index --assume-unchanged <file>

git update-index --assume-unchanged <file>

Now how do you undo it so they are watched again? (Let's call it un-assume.)

现在您如何撤消它以便再次观看它们?(让我们称之为不假设。)

回答by adardesign

To get undo/show dir's/files that are set to assume-unchanged run this:

要撤消/显示设置为假设未更改的目录/文件,请运行以下命令

git update-index --no-assume-unchanged <file>

git update-index --no-assume-unchanged <file>

To get a list of dir's/files that are assume-unchangedrun this:

要获取assume-unchanged运行此目录的目录/文件列表

git ls-files -v|grep '^h'

git ls-files -v|grep '^h'

回答by adswebwork

If this is a command that you use often - you may want to consider having an alias for it as well. Add to your global .gitconfig:

如果这是您经常使用的命令 - 您可能还需要考虑为其设置别名。添加到您的全球.gitconfig

[alias]
    hide = update-index --assume-unchanged
    unhide = update-index --no-assume-unchanged

How to set an alias (if you don't know already):

如何设置别名(如果您还不知道):

git config --configLocation alias.aliasName 'command --options'

Example:

例子:

git config --global alias.hide 'update-index --assume-unchanged'
git config... etc

After saving this to your .gitconfig, you can run a cleaner command.

将此保存到您的 后.gitconfig,您可以运行更干净的命令。

git hide myfile.ext

or

或者

git unhide myfile.ext

This git documentationwas very helpful.

这个git 文档非常有帮助。

As per the comments, this is also a helpful alias to find out what filesare currently being hidden:

根据评论,这也是找出当前隐藏的文件的有用别名:

[alias]
    hidden = ! git ls-files -v | grep '^h' | cut -c3-

回答by Ankit Vishwakarma

git update-index function has several option you can find typing as below:

git update-index 函数有几个选项,你可以找到如下输入:

git update-index --help

Here you will find various option - how to handle with the function update-index.

在这里你会找到各种选项 - 如何处理函数 update-index。

[if you don't know the file name]

[如果你不知道文件名]

git update-index --really-refresh 

[if you know the file name ]

[如果你知道文件名]

git update-index --no-assume-unchanged <file>

will revert all the files those have been added in ignore list through.

将恢复所有已添加到忽略列表中的文件。

git update-index --assume-unchanged <file>

回答by hobbs

I assume (heh) you meant --assume-unchanged, since I don't see any --assume-changedoption. The inverse of --assume-unchangedis --no-assume-unchanged.

我假设(呵呵)你的意思是--assume-unchanged,因为我没有看到任何--assume-changed选择。的倒数--assume-unchanged--no-assume-unchanged

回答by Will Cain

To synthesize the excellent original answers from @adardesign, @adswebwork and @AnkitVishwakarma, and comments from @Bdoserror, @Retsam, @seanf, and @torek, with additional documentation links and concise aliases...

综合来自@adardesign、@adswebwork 和@AnkitVishwakarma 的优秀原始答案,以及来自@Bdoserror、@Retsam、@seanf 和@torek 的评论,以及其他文档链接和简明别名...

Basic Commands

基本命令

To reset a filethat is assume-unchangedback to normal:

重置文件假设未发生变化恢复正常:

git update-index --no-assume-unchanged <file>

To list allfiles that are assume-unchanged:

列出所有那些假设未发生变化的文件:

git ls-files -v | grep '^[a-z]' | cut -c3-

To reset allassume-unchanged files back to normal:

要将所有假定未更改的文件重置为正常:

git ls-files -v | grep '^[a-z]' | cut -c3- | xargs git update-index --no-assume-unchanged --

Note:This command which has been listed elsewhere does not appear to reset all assume-unchanged files any longer (I believe it used to and previously listed it as a solution):

注意:已在别处列出的此命令似乎不再重置所有假定未更改的文件(我相信它曾经并且以前将其列为解决方案):

git update-index --really-refresh

Shortcuts

快捷方式

To make these common tasks easy to execute in git, add/update the following aliassection to .gitconfigfor your user (e.g. ~/.gitconfigon a *nix or macOS system):

为了使这些常见任务在 git 中易于执行,请为您的用户添加/更新以下别名部分.gitconfig(例如~/.gitconfig在 *nix 或 macOS 系统上):

[alias]
    hide = update-index --assume-unchanged
    unhide = update-index --no-assume-unchanged
    unhide-all = ! git ls-files -v | grep '^[a-z]' | cut -c3- | xargs git update-index --no-assume-unchanged --
    hidden = ! git ls-files -v | grep '^[a-z]' | cut -c3-

回答by C0DEF52

If you want to undo all files that was applied assume unchanged with any status, not only cached (git marks them by character in lower case), you can use the following command:

如果要撤消所有已应用的文件,假设不更改任何状态,而不仅仅是缓存(git 以小写字符标记它们),则可以使用以下命令:

git ls-files -v | grep '^[a-z]' | cut -c 3- | tr '2' '
git ls-files -v | grep '^h' | sed 's/^..//' | sed 's/\ /\ /g' | xargs -I FILE git update-index --no-assume-unchanged FILE || true
0' | xargs -0 git update-index --no-assume-unchanged
  1. git ls-files -vwill print all files with their status
  2. grep '^[a-z]'will filter files and select only assume unchanged
  3. cut -c 3-will remove status and leave only paths, cutting from the 3-rd character to the end
  4. tr '\012' '\000'will replace end of line character (\012) to zero character (\000)
  5. xargs -0 git update-index --no-assume-unchangedwill pass all paths separated by zero character to git update-index --no-assume-unchangedto undo
  1. git ls-files -v将打印所有文件及其状态
  2. grep '^[a-z]'将过滤文件并选择仅假设未更改
  3. cut -c 3-将删除状态并只留下路径,从第 3 个字符到结尾
  4. tr '\012' '\000'将行尾字符 (\012) 替换为零字符 (\000)
  5. xargs -0 git update-index --no-assume-unchanged将通过零字符分隔的所有路径git update-index --no-assume-unchanged来撤消

回答by sagunms

Adding to @adardesign's answer, if you want to reset all files that have been added to assume-unchangedlist to no-assume-unchangedin one go, you can do the following:

添加到@adardesign的答案,如果您想一次性重置所有已添加到assume-unchanged列表中的文件no-assume-unchanged,您可以执行以下操作:

##代码##

This will just strip out the two characters output from grep i.e. "h ", then escape any spaces that may be present in file names, and finally || truewill prevent the command to terminate prematurely in case some files in the loop has errors.

这只会去掉 grep ie 输出的两个字符"h ",然后转义文件名中可能存在的任何空格,最后|| true将防止命令过早终止,以防循环中的某些文件出错。

回答by Shivang Gupta

If you are using Git Extensions, then follow below steps:

如果您使用的是Git 扩展,请按照以下步骤操作:

  1. Go to commit window.
  2. Click on the dropdown named Working directory changes.
  3. Select Show assummed-unchanged filesoption.
  4. Right click on the file you want to unassumme.
  5. Select Do no assumme unchanged.
  1. 转到提交窗口。
  2. 单击名为Working directory changes的下拉菜单。
  3. 选择显示假定未更改的文件选项。
  4. 右键单击要取消假设的文件。
  5. 选择不假设不变

You are done.

你完成了。

回答by Tyagi Akhilesh

Nothing here that is not covered. But would like to add my 2 cents. At times, I run a build and it changes lot of files and then I want to work on something, so this command really helps me a lot.

这里没有未涵盖的内容。但想加上我的 2 美分。有时,我运行一个构建,它更改了很多文件,然后我想处理一些事情,所以这个命令真的对我有很大帮助。

git update-index --assume-unchanged `git status | grep modified | sed 's|modified:||g'| xargs`

git update-index --assume-unchanged `git status | grep modified | sed 's|modified:||g'| xargs`

Hope someone else find it useful as well.

希望其他人也觉得它有用。

回答by Steve Chambers

None of the solutions worked for me in Windows - it seems to use capital Hrather than hfor the file status and the grep command requires an extra caret as ^also represents the start of line as well as negating the next character.

在 Windows 中没有一个解决方案对我有用 - 它似乎使用大写H而不是h文件状态,并且 grep 命令需要额外的插入符号,因为它^也代表行的开头以及否定下一个字符。

Windows solution

视窗解决方案

  1. Open Git Bash and change to the relevant top level directory.
  2. git ls-files -v | grep '^^H'to list all the uncached files
  3. git ls-files -v | grep '^^H' | cut -c 3- | tr '\012' '\000' | xargs -0 git update-index --no-skip-worktreeto undo the files skipping of all files that was done via update-index --skip-worktree
  4. git ls-files -v | grep '^^H]' | cut -c 3- | tr '\012' '\000' | xargs -0 git update-index --no-assume-unchangedto undo the files skipping of all files that was done via update-index --assume-unchanged
  5. git ls-files -v | grep '^^H'to again list all the uncached files and check whether the above commands have worked - this should now not return anything
  1. 打开 Git Bash 并切换到相关的顶级目录。
  2. git ls-files -v | grep '^^H'列出所有未缓存的文件
  3. git ls-files -v | grep '^^H' | cut -c 3- | tr '\012' '\000' | xargs -0 git update-index --no-skip-worktree撤消跳过所有文件的文件 update-index --skip-worktree
  4. git ls-files -v | grep '^^H]' | cut -c 3- | tr '\012' '\000' | xargs -0 git update-index --no-assume-unchanged撤消跳过所有文件的文件 update-index --assume-unchanged
  5. git ls-files -v | grep '^^H'再次列出所有未缓存的文件并检查上述命令是否有效 - 现在不应返回任何内容