开发者

Git subtree not properly using .gitignore when doing a partial clone

开发者 https://www.devze.com 2022-12-24 02:55 出处:网络
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 everyth

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~
scrip开发者_开发百科t5.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?


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.


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.


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.

0

精彩评论

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

关注公众号