简体   繁体   中英

git equivalent of Subversion “switch”?

I have some SVN repositories I'm considering switching to git, but they use the Subversion "switch" function in ways I don't know how to emulate in git. How do I do this?

Taking one concrete example: I keep my home directory in SVN. I check it out to many computers where I work. This is very convenient for many things, but not so much for a few. Examples:

  • I have a www/ directory where I build a personal web site. I only work this site from my home machine, and in fact there are files there I don't want to splatter over all the other machines. In the repo itself, this is an empty directory, but when I check the repo out to my home machine, I also switch this directory to an unrelated location in the repo, where www/ actually lives. So most machines just get an empty www/, but selected machines get the contents.

  • I have a Documents/ directory, containing MacOS documents. Lots of them. They're useless on my many Linux machines. For space reasons, I pull the same trick mentioned above: in the repo, Documents is empty, but there's an actual Documents folder, elsewhere in the repo paths, to which I switch Documents/ on Macs.

That is not what the switch command is meant for in the first place.

Anyway, you are looking at using git submodules for what you want. The www and Documents can be seaprate git repositories and you have them as submodules in your main git repository. That way, when anyone clones the repo, they will get empty folders, unless they update the submodules.

If you don't want submodules, you have to explicitly clone separate repos for www and Documents and put in your repo. Note that git doesn't track empty folders so you will not be able to have placeholders for these.

Another way (not really recommended) if you don't want external repos is to create orphan branch with say www:

git checkout --orphan
git rm -rf .
mkdir www
touch www/a
git add www
git commit -m "adding www"
git checkout master
git checkout www -- www

PS: The real git equivalent of svn switch, for what it is intended for is:

git checkout <branchname>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM