git update-index --assume-unchanged on directory 转摘自:http://stackoverflow.com/questions/12288212/git...

 

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.

share |improve this question
 

3 Answers

up vote 36down voteaccepted

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.

share |improve this answer
 
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.

share |improve this answer
 

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
share |improve this answer
 
   
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

转载于:https://www.cnblogs.com/prettyisshit/p/4127877.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值