本地 Git 在复制的项目中

huangapple go评论52阅读模式
英文:

Local git on copied project

问题

我之前有一个项目,我想将其作为新项目的起点,所以我简单地将整个文件夹复制作为新项目的起点。

问题是,现在新项目继承了来自之前项目的Git。我想要移除新项目中的Git,以便使用新的git init。

但是,我不想丢失新项目中的任何代码,也不想丢失旧项目的Git历史记录。

我应该怎么做?

英文:

I had a previous project that I wanted to use as a starting point for a new project, I simply copied the entire folder as a starting point for the new project.

The issue is, now the new project has the git from the previous project. I want to remove git from the new project, in order to use a new git init.

However, I don't want to lose any code in the new project, or any git history from the old project.

How do I do this?

答案1

得分: 2

创建新项目的目录。

将所有文件从旧项目复制到新目录。

在旧项目中删除.git文件夹。

通过以下命令在新项目中初始化新的Git仓库:

$ git init

通过以下命令将旧项目中的所有文件添加到新的Git仓库中:

$ git add .
$ git commit -m "Initial commit"

将新的Git仓库推送到远程仓库(如果有的话,如GitHub、Azure等)。

这将在新项目中创建一个新的Git仓库,不包含旧项目的Git历史或元数据,同时保留旧项目的代码和历史记录在新项目中。

英文:

Create new directory for new project.

Copy all files from old project to new directory.

Remove .git folder in old project.

Init new git repo in new project via $ git init

Add all files from old project to new Git repo through

$ git add .
$ git commit -m "Initial commit"

Push new git repo to remote repo (if any like github, azure etc)

This creates a new Git repo in your new proj, that does not have any Git history or metadata from the old proj, while also preserving code and history from old proj in new proj.

答案2

得分: 2

在新的副本中,删除 .git/ 目录,该目录仅包含有关存储库的 Git 元数据。然后,您可以在新的副本中执行新的 git init,所有相同的文件仍将存在。

由于 .git 目录中的文件可能会受到写保护,您可能需要使用 rm -rf .git 强制删除。只需确保您在正确的目录中。

但是,我不希望丢失新项目中的任何代码,也不希望丢失旧项目的任何 Git 历史记录。

确保您位于新副本目录中,旧目录将完全分开并保持不变。

最好确保您也与远程同步,并且所有分支都已推送,作为备份也是一个好主意。

英文:

in the new copy, remove .git/ directory, which only holds git metadata about the repo. Then you can do a new git init in the new copy and all the same files will still be there.

Since files in .git are likely to be write-protected you may have to force deleteion with rm -rf .git. Just make sure you're in the correct directory.

> However, I don't want to lose any code in the new project, or any git history from the old project.

make sure you're in the new copy directory and the old directory will be completely separate and untouched.

wouldn't hurt to make sure you're in sync with your remote also and all your branches are pushed, just as a backup.

答案3

得分: 1

你所描述的情况听起来像是一个克隆,在这种情况下没有打算将代码推送回原始项目。

首先克隆存储库:

git clone http://example.com/oldrepo.git newrepo

这将把项目克隆到名为newrepo的目录中。

现在,您可以通过删除与上游存储库的任何引用来'取消关联'新存储库:

git remote remove origin

最后,如果您将来要推送到另一个(新的)git存储库,只需添加以下内容:

git remote add origin https://example.com/newrepo
英文:

What you're describing sounds like a clone where there is no intention to ever push code back to the original project.

Start by cloning the repo:

git clone http://example.com/oldrepo.git newrepo

This will clone the project into a directory called newrepo.

Now you can 'disassociate' the new repo from the old one by removing any references to the upstream repository:

git remote remove origin

Finally, if you ever want to push to another (new) git repo in future, just add this instead:

git remote add origin https://example.com/newrepo

huangapple
  • 本文由 发表于 2023年2月18日 01:15:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75487356.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定