Z
Z
zzmaster2017-05-09 12:19:14
git
zzmaster, 2017-05-09 12:19:14

GIT - how to remove files (except ignored ones) from a third-party folder?

Well, I don't know, maybe I want a lot, (git won't even bother to keep track of empty folders ..)
So, I want to clone into a test folder, but before that, clear it of the previous contents. But, since clone does not transfer the files specified via gitignore, this cleanup should not affect these files.
Is that possible?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Z
zzmaster, 2017-05-11
@zzmaster

In general, the problem here is that there are 2 types of ignored files
1 - for example, configs with access to the database
2 - any technical garbage such as caches, logs
When deploying, you need to save the first ones in the target folder and delete the second ones.
Git doesn't have a file like

.gittrash
cache/*

The solution is
cd /path/to/target
git clean -d -f -x --exclude=/path/to/config.php --exclude=/path/to/onemorefile.php
git clone /repo.git .git-i- hate-you
\cp -rf .git-i-hate-you/. .
\rm -rf .git-i-hate-you

why slash? aliases of these commands usually with the -i flag
It is assumed that at least one cloning to the folder has already been done.

I
index0h, 2017-05-09
@index0h

In theory, you are looking for this
git clean -fd

X
xtala zen, 2017-05-09
@xtala

I need to remove the files known to git while keeping the ones defined by gitignore

git rm "globe pattern"
The rm command supports globe patterns just like those in the .gitignore file. For details about global templates, google.
Example :
The command will remove all log files from the current directory.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question