git 1.7.12

I want to mark all files below a given directory as assume-unchanged.

1) git update-index --assume-unchaged dir/ gives "Ignoring path."

2) git update-index --assume-unchaged dir/* quickly fails because it will encounter files which are not being tracked, hence it gives "fatal: Unable to mark file" and quits.

3) Try generating a list of files to mark. cd into the desired directory and then run git ls-files | tr '\n' ' ' | git update-index --assume-unchanged. This produces no error message, but it does not successfully mark the files. The first portion of the command, git ls-files | tr '\n' ' ', correctly produces a space delimited list of all the files I want to mark. If I copy and paste the output of that command onto the command-line, then the git update-index command works. What is not working with the pipes?

No, it is not sufficient for me to add dir to .gitignore. I need these files to be in the repository, but undesired changes will be made locally that need to be ignored so that users can do pulls.

asked Sep 5 '12 at 19:10
 

3 Answers

git update-index wants the file names on it's command line, not on it's standard input. After cding into the folder you want to assume is unchanged, you can do either this:

git update-index --assume-unchanged $(git ls-files | tr '\n' ' ')

or

git ls-files | tr '\n' ' ' | xargs git update-index --assume-unchanged

Although, with either case, file names with spaces will be problematic. If you have those, you can use this:

git ls-files -z | xargs -0 git update-index --assume-unchanged

Edit: incorporated input from @MatthewScharley regarding git ls-files -z.

answered Sep 5 '12 at 20:03
twalberg
20.3k11928
 
2  
Excellent, thank you! The last command did indeed work. –  thoughtadvances Sep 5 '12 at 20:09
    
Thank you so much! –  Mizmor Feb 22 '13 at 19:37
    
FYI, that ` | tr '\n' ' '` bit is unnecessary. –  Václav Slavík May 9 '13 at 8:16
    
@VáclavSlavík You're right... can't remember why I put that in, other than for symmetry with the tr '\n' '\0' case (in which case it is needed)... –  twalberg May 9 '13 at 14:01
2  
@twalberg: You could just use git ls-files -z –  Matthew Scharley Jul 22 '13 at 1:35

The find command from GNU Findutils has a -exec option which removes most of the hassle of using xargs, although its syntax is a little special. It does however deal perfectly with filenames with spaces.

This command will get git to assume all files in and under the listed directory are unchanged:

find path/to/dir -type f -exec git update-index --assume-unchanged '{}' \;

Find takes every argument after -exec until ; (which you have to escape lest your shell eats it) and runs it once for each file found, while replacing {} (again, single quoted so your shell won't eat it) with the found file's name.

Using find's matching criteria (maximum recursion depth, whether the match is a file or is a directory, whether the filename matches an expression) and -exec you can do all sort of powerful things.

Not sure about other implementations of the find command. YMMV.

answered Aug 7 '13 at 18:56
 

Yeap,

git update-index --assume-unchanged

works with files only, not with directories. I think, one of faster ways:

cd dir
ls | xargs -l git update-index --assume-unchanged
answered May 17 '13 at 14:11
 
    
Instead of using cd, you can pass the dir as a final argument: git ls-files -- $DIR | xargs -l git update-index --assume-unchanged -- $DIR. –  kzh Mar 3 at 20:10

git update-index --assume-unchanged on directory 转摘自:http://stackoverflow.com/questions/12288212/git-update-index-assume-unchanged-on-directory的更多相关文章

  1. [原]git的使用(一)---建立本地仓库、add和commit、status和git diff、版本回退使用git reset

    在window下已经安装了git的环境 1.建立本地仓库 mkdir   test     #建立test目录 cd   test        #进入目录 git  init           # ...

  2. Integrates Git with Sublime 3 to pull or push to Github by using Sublime plugin Git

    1. Git must be installed, Sublime plugin "Git" only connects Sublime with Git. Download UR ...

  3. git同步遇到报错“fatal: unable to access 'https://github.com/lizhong24/mysite2.git/': Peer reports incompatible or unsupported protocol version.”

    git同步遇到报错“fatal: unable to access 'https://github.com/lizhong24/mysite2.git/': Peer reports incompat ...

  4. Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.

    问题: Azure Sql 在插入数据是出现“Msg 40054, Level 16, State 1, Line 2  Tables without a clustered index are no ...

  5. git学习3 - 克隆远程库到本地 将本地库上传到git

    如何克隆远程版本库到本地 git clone URL 如何用命令将本地项目上传到git 1.(先进入项目文件夹)通过命令 git init 把这个目录变成git可以管理的仓库 (注意: cd C:/U ...

  6. git fetch批处理,遍历一个文件夹下的所有子目录,执行git fetch --all

    echo off for /d %%i in (*) do ( echo %%i cd %%i git fetch --all cd .. ) 判断子目录是否有.git文件夹 echo off for ...

  7. ThinkPHP 3.2,配置 'URL_MODEL'=>2。 APP_DEBUG设为false,U函数生成的URL的index.php不能去掉,只有将APP_DEBUG改成true,才能去掉index.php,求解~~

    ThinkPHP 3.2,配置 'URL_MODEL'=>2.APP_DEBUG设为false,U函数生成的URL的index.php不能去掉,只有将APP_DEBUG改成true,才能去掉in ...

  8. 一个项目设置两个git地址,并最终实现一次性同时推送到到两个git地址上的方法总结

    基于多处备份的想法,确保自己的代码不丢失.或者是代码的git本身搭建在自己公司的服务上,而你为了保险起见,想把项目同时放在码云或者github上面. 这样,你就需要让一个项目同时备份在两个云端,这样即 ...

  9. Mysql update in报错 [Err] 1093 - You can't specify target table 'company_info' for update in FROM clause

    Mysql update in报错 解决方案: [Err] 1093 - You can't specify target table 'company_info' for update in FRO ...

随机推荐

  1. JS面向对象——原型模型

    以下通过一段示例代码,说明原型模型中的基本概念以及知识点. <!DOCTYPE html> <html> <head> <title>原型模型</ ...

  2. IDEA中添加自定义的方法快捷方式

    IDEA中快速添加自己自定义的方法方法,想要什么快捷方法都行 作为一个从MyEclipse转IDEA的程序员,原来写main就能补全main方法,写syso就能补全System.out.println ...

  3. A星寻路

    逻辑代码 using System.Collections.Generic; using System.Text; using UnityEngine; namespace Game { public ...

  4. Codeforces Round #392 (Div. 2) - B

    题目链接:http://codeforces.com/contest/758/problem/B 题意:给定n个点灯的情况,灯只有四种颜色RBGY,然后如果某个灯坏了则用'!'表示,现在要求将坏的灯( ...

  5. [Linux]Centos7/Centos6更改系统语言

    Centos7系统语言配置信息保存在/etc/locale.conf文件内 更改步骤如下: 1.使用vim打开locale.conf文件 vim /etc/locale.conf2.编辑locale. ...

  6. [CSS布局]简单的CSS三列布局

    前言 公司终于可以上外网了,近期在搞RN的东西,暂时脑子有点晕,等过段时间再来写点总结.倒是最近有个新学前端的同学经常会问一些基础知识,工作空闲写了小Demo给他看,全是很基础的知识,纯粹是顺便记录在 ...

  7. 【python实例】判断是否是回文数

    """ 输入一个数,判断一个这个数是否是回文数.例如:121,这个数反过来还是121,所以这个是回文数: 再如:134,这个数反过来是431,所以这不是一个回文数: 12 ...

  8. Calendar日历

    Calendar calendar=Calendar.getInstance(); //上一年的今天 calendar.add(Calendar.YEAR,-1); System.out.printl ...

  9. Codefroces 958C2 - Encryption (medium) 区间dp

    转自:https://www.cnblogs.com/widsom/p/8857777.html     略有修改 题目大意: n个数,划分为k段,每一段的和mod p,求出每一段的并相加,求最大是多 ...

  10. Jenkins之配置GitHub-Webhook2

    什么是持续集成(Continuous integration) 提出者Martin Fowler本人对持续集成是这样定义的:持续集成是一种软件开发实践,即团队开发成员经常集成他们的工作,通常每个成员每 ...