如何将项目的备份副本手动导入到 Git 中?

发布于 2024-12-22 12:44:41 字数 60 浏览 0 评论 0原文

在手动创建我的小项目的分支和副本之后,我终于在没有经验的情况下尝试使用 git。如何导入所有这些手动副本?

After manually making branches and copies of my small project, I'm finally trying using git with no experience. How do you import all of these manual copies?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绳情 2024-12-29 12:44:41

如果您觉得值得将所有旧历史记录导入 Git,那么就可以这样做。然而,手动导入历史记录可能非常繁琐,尤其是对于多个分支。有些人编写了脚本将现有 VCS 中的代码导入到 Git 中,但显然这不能直接用于手动副本。

我会考虑您是否真的需要 Git 中的所有历史副本。如果没有,请开始对当前代码使用基本的 Git 操作,并从现在开始继续。

如果您仍然想手动导入历史记录,可以通过以下简单方式进行操作:

# create a new repository in the current directory
git init

# get snapshot #1 from files1
cp ~/backup/files1/* .
git add .
git commit -m "files1 snapshot"

# get shapshot #2 from files2
cp ~/backup/files2/* .
git add .
git commit -m "files2 snapshot"

# get snapshot in files_test into test_branch
git checkout test_branch
cp ~/backup/files_test/* .
git add .
git commit -m "files_test snapshot on branch test_branch"

如果您在修订之间删除了文件,则还必须使用 git rm 以及 git add 来完整记录历史。高级使用上述内容可以让您将提交日期和时间从当前时间更改为您喜欢的任何时间戳。

If you feel that it's worthwhile to import all your old history into Git, it's possible to do so. However, manually importing history can be pretty tedious, especially with multiple branches. Some people have written scripts to import code in an existing VCS into Git, but obviously that wouldn't directly work for your manual copies.

I would consider whether you really need all the historical copies in Git. If not, then start using the basic Git operations with your current code and move forward from now.

If you still want to manually import history, here's how you could do it in a simple manner:

# create a new repository in the current directory
git init

# get snapshot #1 from files1
cp ~/backup/files1/* .
git add .
git commit -m "files1 snapshot"

# get shapshot #2 from files2
cp ~/backup/files2/* .
git add .
git commit -m "files2 snapshot"

# get snapshot in files_test into test_branch
git checkout test_branch
cp ~/backup/files_test/* .
git add .
git commit -m "files_test snapshot on branch test_branch"

If you have removed files between revisions, you'll also have to use git rm as well as git add to fully record history. Advanced use of the above can let you change the commit date and time from the current time to whatever timestamp you like.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文