Reputation: 46060
I have a website project that has more than 50,000 unimportant files (to development) in some directories.
/website.com/files/1.txt
/website.com/files/2.txt
/website.com/files/3.txt
/website.com/files/etc.txt
The stuff in /files is already in the repo. I want to delete all the files in /files on my local copy but I want git to ignore it so it doesn't delete them when I do a pull on the web server.
Any ideas?
Upvotes: 24
Views: 28537
Reputation: 4812
As @dave1010 pointed out, you have to mark each individual file.
If you don't have awk
and bash
, such as for Windows, you can use the following Perl script:
foreach (split("\n",`git status`)) {
if (/^\s+deleted:\s+(.+)$/) {
`git update-index --assume-unchanged $1`;}}
Any Perl for Windows such as Strawberry Perl, works. You can also write a PowerShell script for Windows, but Perl is universal.
Upvotes: 0
Reputation: 12095
The code below works on deleted as well as modified files to ignore it when you do a git status.
git update-index --assume-unchanged dir-im-removing/
or a specific file
git update-index --assume-unchanged config/database.yml
Ignore modified (but not committed) files in git?
Beware: The suggestion above for deleted files when you do a "git commit -am " includes the deleted file!
A solution that would work for me is to instead of deleting the file, just make it's content blank. This is what I used to mute a .htaccess file.
Upvotes: 13
Reputation: 131
for i in `git status | grep deleted | awk '{print $2}'`; do git update-index --assume-unchanged $i; done
works with git 2.25.1
if you encounter this issue:
fatal: Unable to mark file PATH/TO/FILE
check there is no space in the file path and use quotes instead
Upvotes: 0
Reputation: 476
To commit only added / modified files (and NOT removed ones) do:
git add . --ignore-removal
git commit -m "commit message"
Upvotes: 1
Reputation: 15435
Ignoring a whole directory didn't work. I had to do this:
for i in `git status | grep deleted | awk '{print $3}'`; do git update-index --assume-unchanged $i; done
Upvotes: 16
Reputation: 1328712
Creating a sub-repo is one solution, but you should make that sub-repo a submodule.
That way:
git submodule update
" (that is without filling the 'files
' contentgit submodule update
after the git submodule init
will be enough to get back the right version of the 'files
' content.Upvotes: 3
Reputation: 46060
Ok Ive found a solution. Simply create a new repo in the sub directories and the parent repo will ignore them.
Upvotes: 3