8

I am a graduate student with many scripts, bibliography data in bibtex, thesis draft in latex, presentations in open office, posters in scribus, and figures and result data. I would like to put everything in one project under version control. Then when I need to work on a portion such as the bibliography data, I would like to check that subdirectory out, modify it as necessary and merge it back.I would like the ability to check out one version to my home computer, and a different one to my work computer and make changes to each independently and eventually merge them back. I would also like to be able to check out a piece of code from this big project and import it with versioning into a separate project. If I may changes I'd like to be able to merge them back to the original project.

Based on my understanding git subtree can do this.

http://github.com/apenwarr/git-subtree

There is an example that is along the lines of what I'm trying to do at:

http://psionides.jogger.pl/2010/02/04/sharing-code-between-projects-with-git-subtree/

Say the trunk of my project contained the directories: (bib bin cfg data fig src todo).

When I use

git subtree split -P bib -b export
git checkout export

I get a the bib directory, plus all files that should have been ignored or considered binary based on .gitignore such as the src directory and everything in it that ends in a tilde or the ./data directory.

dwickrama@DWwork:~/research/trunk$ ls * -r
biblography.bib  JabRef

src:
script1.sh~ README~         script2.sh~
script3.sh~ script4.R~  script5.awk~
script5.py~ 

cfg:
cfgFile1.ini~  cfgFile2.ini~  cfgFile3.ini~

bin:
bigBinaryPackage1   bigBinaryPackage2

dwickrama@DWwork:~/research/trunk$ 

My .gitignore file is as follows:

*.doc diff=word
*.tex diff=tex
*.bib diff=bibtex
*.py diff=python
*.eps binary
*.jpg binary
*.png binary
./bin/* binary
*~

How do I prevent this?

11
  • 1
    Have you looked into using submodules? They're designed for this sort of thing, and a bit more automated...
    – Cascabel
    Mar 23, 2010 at 21:41
  • 1
    Thank you for the comment. Subtree supposedly has many advantages outlined at: apenwarr.ca/log/?m=200904#30
    – D W
    Mar 23, 2010 at 21:48
  • 1
    I don't see the first example on the site you linked (maybe it's in the git-subtree docs). The second, though, is similar to one on the tutorial blog post - except you've left off the -b option, which creates a branch for the subtree. Is that what you meant to do? (I think yours is probably just printing the SHA1 of the subtree)
    – Cascabel
    Mar 23, 2010 at 22:03
  • 1
    @D W: I think you really need to read and understand the walkthrough on that blog. I'm just retyping things that are already written there. For this particular step, you're not actually creating a new directory. You're creating a branch within the same repository which represents only that subtree. From there, you can make another repo containing only that branch - that's the very next step in the tutorial.
    – Cascabel
    Mar 23, 2010 at 22:20
  • 2
    @D W: Ignored files are of course not removed when you check out a different branch. And on the other branch, they're not ignored, because the .gitignore is not part of that subtree! If you create a separate repo and fetch from this branch (as shown in the tutorial) those files won't be brought over - they're not tracked, they're just remaining around through the checkout.
    – Cascabel
    Mar 24, 2010 at 0:09

3 Answers 3

5

Looks to me like all those ignored files aren't actually in your repo - they're just leftover from your previous checkout.

Since you extracted a particular subtree from your original project, your .gitignore file is no longer present, so the files are no longer being "ignored", so you'll see them in git status. But they also aren't part of your repo; they're just sitting there.

Try using 'git clean' to clean them up.

1
  • What about environment stuffs such as node_modules or vendor? Jul 18, 2016 at 11:35
4

I think this isn't anything really specific to git-subtree, you'd have the same situation if you switched between two branches and one of them generated some extra files that were in gitignore and the other wouldn't know about them... I'd say this behavior of git is rather correct, because if I add a file to gitignore, I expect it will completely ignore it and won't do anything with it - that includes also not deleting it when you move to a branch where it's not gitignored...

The possible ways you can deal with this would be:

  • add the same files also to the gitignore in subdirectory/subproject
  • do git clean before you switch branches
  • just ignore this, after all, you probably won't do much work in the branch that was generated by git subtree split other than pushing the commits outside... if you do want to work on the subproject separately, then maybe just checkout the subproject itself in another directory outside the main one.
1

Your .gitignore file is incorrectly mixing gitignore syntax with gitattributes syntax.

The .gitignore file should only have patterns. Stuff like

*.py diff=python
*.eps binary

belongs in the .gitattributes file instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.