Is it safe to use a copied git repo?

前端 未结 3 1012
南笙
南笙 2021-02-11 16:32

If I make a copy of a tracked folder using rsync -a or cp -R, can I then use the copy as if it were a git clone, or will that cause all sorts of weird

相关标签:
3条回答
  • 2021-02-11 17:01

    When you clone someone else’s repository, it basically just copies the contents of this directory to your computer.

    From the real good Git Internals (Scott Chacon) from Peepcode Press. (Page 44) So just the reference to the origin is missing as far as I'm concerned/I see.

    With best regards.

    0 讨论(0)
  • 2021-02-11 17:02

    It's exactly the same, well, almost, if you want the same in 'project3' just do:

    git remote add origin /home/itsadok/project
    git branch -f master origin/master
    
    0 讨论(0)
  • 2021-02-11 17:14

    It is safe.

    The difference in using "git clone" is that it automatically sets up the origin repository, so that you can easily use "git pull" and "git push" to synchronize the two repositories. Also "git clone" does not copy the logs, index and other configuration that is local to a repository. It only copies the version history of the repository (and even that can be stored at byte-level differently, because Git every now and then compresses its database when using "git gc").

    Those differences that you see in your example are because rsnc copied also the working directory index, logs and because the rsync-copy did not set up the remote origin. There are quite many configuration and log files that are local to a repository. But there is no danger in copying them directly, for example when restoring backups or moving the repository to another directory/harddrive/machine.

    0 讨论(0)
提交回复
热议问题