简体   繁体   English

将git以外的代码合并到现有的git项目中

[英]merging code outside of git into an existing git project

I have an existing git project, let's call it BobCrane. 我有一个现有的git项目,我们称其为BobCrane。 This needed to completely re-work this project's extensive directory structure. 这需要完全重新设计该项目的广泛目录结构。

I created the needed directory structure on the filesystem, outside of any git project. 我在任何git项目之外的文件系统上创建了所需的目录结构。 I then manually copied each file from the cloned BobCrane repo into this new directory structure. 然后,我从克隆的BobCrane存储库中手动将每个文件复制到此新目录结构中。 So the new directories are filled with old files; 因此,新目录中充满了旧文件; there are only one or two new ones that didn't exist before. 只有一两个新的不存在。

How can I add/commit/push this new structure to the existing git repo? 如何将这个新结构添加/提交/推送到现有的git repo? Is this related to "rebasing"? 这和“变基”有关吗?

  1. init a git repository at new directory structure 在新目录结构中初始化git存储库
git init
  1. commit all files 提交所有文件
git add -A
    git commit -m "commit message"
  1. add your existing repository remote 添加您现有的资源库远程
git remote add origin your_existing_repository@url


Merge approach 合并方式

  1. pull changes from remote 从远程拉取更改
\n    git pull origin remote_branch_name git pull origin remote_branch_name\n
  1. after resolving all conflicts execute 解决所有冲突后执行
\n    git add -A git添加-A\n    git merge --continue git merge-继续\n


Rebase approach 变基方法

  1. Fetch changes from remote 从远程获取更改
git rebase origin/remote_branch_name

5.1. 5.1。 Rebase onto remote branch 重新定位到远程分支

git add -A
    git rebase --continue

5.2. 5.2。 Resolve conflicts if any and execute 解决冲突(如果有)并执行

\n    git add -A git添加-A\n    git rebase --continue git rebase-继续\n


6. push new commits into your existing repository 6.将新提交推送到您现有的存储库中

\n    git push -u origin remote_branch_name git push -u原始remote_branch_name\n


Rebase is preferred way because it will produce cleaner commits history Rebase是首选方法,因为它将产生更干净的提交历史记录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM