69

I'm trying to exclude subversion's folders from being tracked by git. I tried a couple different setups for .git/info/exclude, but it doesn't seem to work. I would use git-svn, but it's a pain to request access to get that to work, so I'd rather just work around this by excluding the folders.

I want to exclude ".svn/entries"

I've tried adding the following lines to .git/info/exlude: .svn entries .svn/entries entries svn

No matter what I try, .svn entries shows up when I run git status

Luke Stevenson
  • 10,357
  • 2
  • 26
  • 41
johannix
  • 29,188
  • 15
  • 39
  • 42
  • what do you mean its a pain to request access to get git-svn to work. git-svn just issues svn commands so if you already have SVN access you can use git-svn without anyone upstream knowing at all or needing to change anything – cpjolicoeur May 04 '09 at 20:29
  • Access to install things on my work computer. There's a perl module missing, and to ask the admins to make that mod, is just a pain... – johannix May 04 '09 at 20:33

7 Answers7

50

I think you want to use a .gitignore file in your top-level directory. This will work if you put ".svn/entries" on a line in that file. You might just put ".svn" instead of ".svn/entries" as well.

EDIT: See comments. If they files are already being tracked by git, they'll always show up in git status.

Jesse Rusak
  • 56,530
  • 12
  • 101
  • 102
  • 2
    I tried this too, and this didn't work. The problem is that each folder has its own .svn/entries. – johannix May 04 '09 at 20:36
  • 4
    This works for me, even in the presence of one in each folder. Are the entries showing up in `svn status` because you've already asked git to track them? If you've `git add`ed them, they'll show up no matter what. Just `git rm --cached` them and you'll be OK. – Jesse Rusak May 04 '09 at 20:40
  • There it is. I started by adding all the files in trunk... Good catch Jesse! – johannix May 04 '09 at 20:49
  • 4
    Not the most elegant thing in the world, but I used the following to recursively strip .svn folders (as per @JesseRusak): `for dir in $(find ./ -type d); do git rm --cached -r $dir/.svn; done;` – hayesgm Oct 10 '11 at 05:17
  • I just removed all the old .svn directories using this: http://stackoverflow.com/a/1294608/308315 – iwasrobbed Dec 22 '12 at 06:12
  • 2
    ghayes's rule is dangerous and potentially a security issue if someone has placed filenames with commands embedded in them. Or it might just fail because for example a filename has a space in it. I suggest this variant instead: `find ./ -type d -name .svn -print0 | xargs -0 git rm --cached -r` – mc0e Sep 30 '13 at 06:20
30

This thread has the correct answer:

Git - Ignore certain files contained in specific folders

What you really need is:

.svn*
Community
  • 1
  • 1
RoloDMonkey
  • 401
  • 4
  • 3
25

Put ".svn" in a ~/.gitexcludes file. Then tell git about it:

echo '.svn' > ~/.gitexcludes
git config --global core.excludesfile "/home/USER_NAME/.gitexcludes"

(Make sure you change USER_NAME so it points to your home directory)

ErichBSchulz
  • 15,047
  • 5
  • 57
  • 61
cmcginty
  • 113,384
  • 42
  • 163
  • 163
5

This following structure and .gitignore contents worked for me

  • \.git
  • \.svn
  • \.gitignore

.gitignore contents

.svn/
.gitignore
konsolenfreddy
  • 9,551
  • 1
  • 25
  • 36
harryhazza
  • 117
  • 1
  • 4
  • 7
    [Don't tell Git to ignore the `.gitignore`!](http://stackoverflow.com/questions/767147/how-do-i-tell-git-to-ignore-gitignore) – Bengt Jun 23 '13 at 23:22
3

if you want to keep the svn directory.

you may run the following first:

for dir in $(find ./ -type d -name \*.svn); do git rm --cached  -r $dir; done;

and then run echo ".svn" >>.gitignore in the root directory

3

Do what Casey suggests, except name the file .gitignore and put it in the root of your git repo.

I also like to do a attrib +h .gitignore so it won't show up in my explorer windows.

Andrew Burns
  • 13,917
  • 9
  • 40
  • 42
2

since every versioned folder has a .svn directory you have to put:

*/.svn/*

nils petersohn
  • 2,317
  • 2
  • 25
  • 27