I got PC from previous developer. There are many untracked files and folders (>400) in git. Project should work without them, but I don't want to delete or stash them. Maybe I'll have some usage later.
Is there way to move them with structure to Backup folder out of git?
Based on this answer, you can do something like follow assuming your can use bash command (I guess you can do this in git prompt).
cd $Git_Repo
for file in $(git ls-files --others --exclude-standard); do mkdir -p ../backup/$(dirname $file) ; mv $file ../backup/$file ; done
The last command loops on all untracked files, creates structure (dirname
) in backup destination folder file. It moves file where it needs.
NOTE: If you have filenames with spaces, you have to specify the delimiter IFS for bash during your command (source). Do not forget to unset this after. The command becomes
cd $Git_Repo
IFS=$'\n'
for file in $(git ls-files --others --exclude-standard); do mkdir -p ../backup/$(dirname $file) ; mv $file ../backup/$file ; done
unset IFS
rsync -R `git ls-files --others` ../Backup
git ls-files --others
lists untracked files including ignored; if you want to exclude files listed in .gitignore
add --exclude-standard
.
rsync -R
copies the listed files into ../Backup
directory preserving paths.
After that cleanup worktree with git clean -fd
or even git clean -fdx
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With