开发者

How do you gitignore everything except a directory?

开发者 https://www.devze.com 2023-01-08 17:48 出处:网络
I am trying to sync my desktop and laptop using a cron\'d git. It works beautifully on a single directory. However I want to sync multiple co开发者_StackOverflownfig files scattered about and some oth

I am trying to sync my desktop and laptop using a cron'd git. It works beautifully on a single directory. However I want to sync multiple co开发者_StackOverflownfig files scattered about and some other things. To do this decided to turn my home folder into a git directory and ignore everything except for a few select files and directories.

$ cat .gitignore
*
# test is a directory
!test

Does not work. Looking at another stackoverflow question, I found */ and used it instead of *. That almost worked as I wanted it to, but then all of the random single hidden files I have scattered about my home directory showed up.


From my git ignore in my home directory.

*

Then you have to git add -f stuff you want to commit. Least that is how I do it for my configs.


What works for me:

# Ignore every directory
/*
# Except this one
!/test

Or

# Ignore every file
*
# Except these ones
!test
!test/*
!test/*/*


Try:

!test/*

instead. I'm not sure if this will work (wild guess), but it is worth a try.


$ cat .gitignore
**/*
*
# test is a directory
!test
0

精彩评论

暂无评论...
验证码 换一张
取 消