180

不久前,我这样做是为了忽略对 git 跟踪的文件的更改:

git update-index --skip-worktree <file>

现在我实际上想将该文件的更改提交到源。如何撤消 的影响skip-worktree

4

8 回答 8

250

啊哈!我只是想要:

git update-index --no-skip-worktree <file>
于 2012-06-21T03:43:17.760 回答
38

根据http://www.kernel.org/pub/software/scm/git/docs/git-update-index.html,使用

git ls-files -v

查看标有特殊字母的“假设不变”和“跳过工作树”文件。“skip-worktree”文件标有S.

编辑:正如@a​​macleod提到的,创建一个别名来列出所有隐藏文件是一个很好的技巧,这样你就不需要记住它了。我alias hidden="git ls-files -v | grep '^S'"在我的 .bash_profile 中使用。效果很好!

于 2012-11-26T15:59:50.353 回答
24

如果要撤消所有应用跳过工作树的文件,可以使用以下命令:

git ls-files -v | grep -i ^S | cut -c 3- | tr '\012' '\000' | xargs -0 git update-index --no-skip-worktree
  1. git ls-files -v将打印所有文件及其状态
  2. grep -i ^S将过滤文件并仅选择跳过工作树 (S) 或跳过工作树并假设未更改 (s),-i 表示忽略大小写敏感
  3. cut -c 3-将删除状态并只留下路径,从第 3 个字符切到末尾
  4. tr '\012' '\000'将行尾字符 (\012) 替换为零字符 (\000)
  5. xargs -0 git update-index --no-skip-worktree将所有由零字符分隔的路径传递git update-index --no-skip-worktree给撤消
于 2015-12-31T22:02:52.170 回答
9

对于所有喜欢 Bash 别名的人,这是我的一套来统治它们(基于 C0DEF52)

alias gitskip='git update-index --skip-worktree ' #path to file(s)
alias gitlistskiped='git ls-files -v | grep ^S'
alias gitunskip='git update-index --no-skip-worktree ' #path to file(s)
alias gitunskipall='git ls-files -v | grep -i ^S | cut -c 3- | tr ''\\012'' ''\\000'' | xargs -0 git update-index --no-skip-worktree'
于 2020-03-26T21:02:39.873 回答
8

基于@GuidC0DE 的回答,这是 Powershell 的一个版本(我使用posh-git

git update-index --no-skip-worktree $(git ls-files -v | sls -pattern "^S"| %{$_.Line.Substring(2)})

并且作为参考还有隐藏文件的相反命令:

git update-index --skip-worktree $(git ls-files --modified)
于 2017-07-10T09:19:25.767 回答
5

对于那些使用 Tortoise Git 的人:

  1. 右键单击文件夹或特定文件,然后选择TortoiseGit > Check for modifications
  2. 只检查Show ignore local changes flagged files. 您应该会看到您忽略的文件(或您忽略的所有文件,如果您右键单击该文件夹)
  3. 右键单击文件并选择Unflag as skip-worktree and assume-unchanged
于 2019-01-25T00:50:44.823 回答
0

此答案针对使用 Windows 的技术含量较低的人。

如果您不记得/不知道您在哪些文件上单击了“skip-worktree”,请使用:

git ls-files -v             //This will list all files, you are looking for the ones with an S at the beginning of the line. 

git ls-files -v | grep "S " //Use this to show only the lines of interest. Those are the files that have "skip-worktree".

要解决您的问题:

您可以转到文件->右键单击->恢复到以前的版本->单击顶部的“git”选项卡->取消选中“skip-worktree”复选框->单击底部的“应用”。

如果文件太多而无法手动修复,那么您需要参考其他答案。

于 2020-07-24T08:31:51.713 回答
0

如果您是 PowerShell 用户,这里有一些受 @yossico 的 bash 别名启发的函数(别名)

<#
Command: gitskipped
Description: List skipped files in git
Usage: gitskipped
#>
function gitskipped {
  (git ls-files -v $args) -split "\r\n" | Select-String -Pattern '^S ' | ForEach-Object {
    Write-Output $_.Line.Substring(2)
  }
}


<#
Command: gitskip
Description: Mark file(s) as "skip-worktree" in git
Usage: gitskip .env
#>
function gitskip {
  git update-index --skip-worktree $args
}


<#
Command: gitunskip
Description: Unmark file(s) as "skip-worktree" in git
Usage: gitunskip .env
#>
function gitunskip {
  git update-index --no-skip-worktree $args
}


<#
Command: gitunskipall
Description: Unmark all skipped files in git
Usage: gitunskipall
#>
function gitunskipall {
  $files = @((git ls-files -v $args) -split "\r\n" | Select-String -Pattern '^S ' | ForEach-Object { $_.Line.Substring(2) })
  git update-index --no-skip-worktree $files
}
于 2021-08-06T19:19:51.057 回答