Exact `svn export` equivalent command for git?

2020-05-27 11:37发布

问题:

There is no exact svn export equivalent command for git? Really?

Beware: this is not a duplicate question. That is, I already know and have tested these commands:

  • git clone --depth 1 <- Still downloads the .git folder.
  • git checkout-init <- Doesn't work for a remote repo, it works with a working copy (so you need to clone first).
  • git archive <- This would be the perfect solution, because it has a --remote argument, but it only has 2 possible formats: tar or zip, so I would need to untar/unzip after downloading, and for that I need a pipe (|), but I'm on windows!! (not *n?x)
  • git clone --bare <- I still don't know what the heck this is, but it's not what I need.

Please enlighten me is there a real svn export replacement in git?

回答1:

At some hostings like GitHub you can make exact svn export.

Example:

svn export https://github.com/GNOME/banshee/branches/master

Even partial! (some subpart of the repository)

Example:

svn export https://github.com/liferay/liferay-portal/branches/6.1.x/tools

For your own repository you should create some GitHub repository and add it as a remote:

git remote add github https://github.com/<user>/<repo>.git

then

git push github <branch>

Now you able to do a partial checkout as above.



回答2:

From How do I do a quick clone without history revisions?:

git clone --depth 1 your_repo_url

Then, from the rmdir documentation:

rd /s /q .git


回答3:

The question "how can I do a svn-style 'export' with git?" is like asking "How can I change the tires on my basketball?". You can't, but that's not the basketball's fault. Yes it is rubber and full of air, but the similarity ends there.

You only need "export" with svn because it pollutes every single subdirectory with a .svn directory. Git doesn't do that, so you really don't need it. A clone IS an export, just with one directory at the root dir that all the repository business lives in.

The easiest thing is to clone the repo and then just delete the .git directory from the top level of the repo. Do that, and it's not a repo anymore, it's just a stand-alone directory of files.

Or, you know, ignore git all together and just use the files you cloned down. That works too.



回答4:

Just get rid of the repository within the working copy.

git clone remote
rm -Rf .git

(On Windows, it's rd /s /q. Thanks for the hint by @Bruno.)



回答5:

For your I still don't know what the heck this is: git clone --bare will clone the repository without a working copy. This is usually done on a central repository so as to minimise disk space usage.

Bruno / King Crunch have the best answer. Although you could use git bash / cygwin to allow you to pipe if you need a one-liner.



回答6:

Re your point, git archive <- This would be the perfect solution ...but it only has 2 possible formats: tar or zip, you can add new formats using documentation from the EXAMPLES section of the git-archive(1) man page:

   git config tar.tar.xz.command "xz -c"
       Configure a "tar.xz" format for making LZMA-compressed tarfiles.
       You can use it specifying --format=tar.xz, or by creating an output
       file like -o foo.tar.xz.

While being "on windows" is generally considered an impediment to many tasks, with a little extra work, you can almost catch up to the folks running other operating systems by using software like Cygwin or MKS Toolkit.

If after confirming that whatever command you need is available from within your shell, this sort of git config … command still doesn't work for you, then you should perhaps post additional details about your configuration in a question on SuperUser.com.



回答7:

From https://stackoverflow.com/a/160719/43597

git checkout-index -a -f --prefix=/destination/path/