How do I convert simple non source controlled project backups into a versioned git repository?

前端 未结 5 703
孤独总比滥情好
孤独总比滥情好 2021-01-04 22:15

I have been extremely naughty. I have been developing a piece of software (I\'m the only developer) for a little while (O.K., it\'s over the course of a few years), but have

5条回答
  •  别那么骄傲
    2021-01-04 22:56

    If you are using import-tars importer (in contrib/fast-import/), know that it used to create phony files at the top-level of the repository when the archive contains global PAX headers (to register commits), which made its own logic to detect and omit the common leading directory ineffective, which has been corrected with Git 2.27 (Q2 2020).

    See commit c839fcf (24 Mar 2020) by Johannes Schindelin (dscho).
    (Merged by Junio C Hamano -- gitster -- in commit 8633f21, 22 Apr 2020)

    import-tars: ignore the global PAX header

    Signed-off-by: Johannes Schindelin

    The tar importer in contrib/fast-import/import-tars.perl has a very convenient feature: if all paths stored in the imported .tar start with a common prefix, e.g. git-2.26.0/ in the tar at https://github.com/git/git/archive/v2.26.0.tar.gz, then this prefix is stripped.

    This feature makes a ton of sense because it is relatively common to import two or more revisions of the same project into Git, and obviously we don't want all files to live in a tree whose name changes from revision to revision.

    Now, the problem with that feature is that it breaks down if there is a pax_global_header "file" located outside of said prefix, at the top of the tree.

    This is the case for .tar files generated by Git's very own git archive command: it inserts that header, and git archive allows specifying a common prefix (that the header does _not_ share with the other files contained in the archive) via --prefix=my-project-1.0.0/.

    Let's just skip any global header when importing .tar files into Git.

    Note: this global header might contain useful information.
    For example, in the output of git archive, it lists the original commit, which _is_ useful information.

    A future improvement to the import-tars.perl script might be to include that information in the commit message, or do other things with the information (e.g. use mtime information contained in the global header as date of the commit).
    This patch does not prevent any future patch from making that happen, it only prevents the header from being treated as if it was a regular file.

提交回复
热议问题