Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
663 views
in Technique[技术] by (71.8m points)

command line - git update-index --assume-unchanged on directory

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 ' ' ' ' | 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 ' ' ' ', 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.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

git update-index wants the file names on its command line, not on its standard input.

Step 1:

cd into the folder you want to assume is unchanged

Step 2:

You can do either this:

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

or

git ls-files | tr '
' ' ' | 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.

Windows Commands

Note: If you're on windows, use Git Bash to run these commands


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...