【问题标题】:Undo git update-index --skip-worktree撤消 git update-index --skip-worktree
【发布时间】:2012-06-23 06:38:33
【问题描述】:

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

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

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

【问题讨论】:

标签: git undo


【解决方案1】:

啊哈!我只是想要:

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

【讨论】:

  • 我爱啊哈!
  • 谁会喜欢它
  • 啊哈! =尤里卡! :D
  • 我本来可以编出来的!
  • 为什么最好的答案在页面底部
【解决方案2】:

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

git ls-files -v

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

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

【讨论】:

  • 整洁。我可以使用git ls-files -v | grep '^S' 仅列出我用跳过工作树“隐藏”的文件。希望为该命令创建一个“隐藏”别名,但在别名中放置管道重定向似乎不起作用。
  • @amacleod 使用!。像这样[alias] ignored = !git ls-files -v | grep "^S" 测试,有效。
  • @amacleod 不要以为您可以为 Windows 推荐一个替代命令?
  • @SteveChambers,没有安装grep,我不知道。取决于你的外壳,我猜。我认为 Git Bash 确实带有 grep
  • 太棒了,谢谢@amacleod - 只是不在我的路上。为了在 Windows 上运行,我唯一需要更改的是引用样式 - ' 不起作用但 " 起作用,即 git ls-files -v | grep "^S"
【解决方案3】:

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

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- 将删除状态并只留下路径,从第三个字符切到结尾
  4. tr '\012' '\000' 会将行尾字符 (\012) 替换为零字符 (\000)
  5. xargs -0 git update-index --no-skip-worktree 会将所有以零字符分隔的路径传递给git update-index --no-skip-worktree 以撤消

【讨论】:

  • 这是最好的答案
  • 这个答案是纯金!
【解决方案4】:

对于所有喜欢 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'

【讨论】:

    【解决方案5】:

    基于@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)
    

    【讨论】:

      【解决方案6】:

      对于那些使用 Tortoise Git 的人:

      1. 右键单击文件夹或特定文件,然后选择TortoiseGit &gt; Check for modifications
      2. 只检查Show ignore local changes flagged files。您应该会看到您忽略的文件(或您忽略的所有文件,如果您右键单击该文件夹)
      3. 右键单击文件并选择Unflag as skip-worktree and assume-unchanged

      【讨论】:

        【解决方案7】:

        此答案面向使用 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”复选框->单击底部的“应用”。

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

        【讨论】:

        • 请说明您使用的是乌龟git还是?
        【解决方案8】:

        如果您是 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
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-06-16
          • 2021-12-24
          • 1970-01-01
          • 2021-09-30
          • 1970-01-01
          • 2011-08-31
          • 2018-03-03
          相关资源
          最近更新 更多