简体   繁体   English

当我想从git repo中删除所有文件然后添加新文件时,如何避免冲突

[英]how to avoid conflict when I want to remove all files from git repo and then add new files

(Editing the question :) (编辑问题:)

I have 2 repository in github, These repositories are http://github.com/abc.git and http://github.com/xyz.git . 我在github中有2个存储库,这些存储库是http://github.com/abc.githttp://github.com/xyz.git

Now the repository "abc.git" was the main repo for the project. 现在,存储库“abc.git”是该项目的主要回购。 After about a month of development we found we could do better by making re-useable code. 经过大约一个月的开发,我们发现通过制作可重复使用的代码可以做得更好。 So we decided to create a new repo for a - reusable generic code base ie xyz.git. 所以我们决定为一个可重用的通用代码库创建一个新的repo,即xyz.git。 So now we have 所以现在我们有了

  1. abc.git (very project specific code + external module + code "that we want to re-write") abc.git(非常项目特定代码+外部模块+代码“我们要重写”)
  2. xyz.git (code "we made re-useable" + external module) xyz.git(代码“我们可以重复使用”+外部模块)

Now code that we made re-useable is basically we added some new files, delete some old files and modified in xyz.git. 现在我们重新使用的代码基本上是我们添加了一些新文件,删除了一些旧文件并在xyz.git中进行了修改。 This code originally comes from the code "we want to re-write" from abc.git. 此代码最初来自abc.git中的“我们要重写”代码。

So far so good I hope :) 到目前为止,我希望:)

Now we have 2 options 现在我们有2个选项

  1. create a new repo say project.git, add a new remote repo ie xyz.git and merge and pick the files we need from abc.git. 创建一个新的repo说project.git,添加一个新的远程仓库,即xyz.git,并合并并从abc.git中选择我们需要的文件。 So in terms of commands the following 所以在命令方面如下

    • the whole github new repo creation process and add a README file. 整个github新的repo创建过程并添加一个README文件。 (this is my project.git origin) (这是我的project.git来源)
    • git remote add xyz git@github.com:xyz.git git remote add xyz git@github.com:xyz.git
    • git checkout -b xyz git checkout -b xyz
    • git pull xyz master git pull xyz master
    • git status git状态
    • git checkout master git checkout master
    • git merge xyz git merge xyz
    • git commit -a git commit -a
    • git push origin master git push origin master

Now we have project.git populated with xyz.git + README and start the hard work of cherry picking files from abc.git (which I want to avoid also I miss out on all the old history) 现在我们使用xyz.git + README填充project.git并开始从abc.git中挑选樱桃的辛勤工作(我想避免,我也错过了所有旧历史)

  1. What I thought I could do is delete all the files from abc.git and bring back the xyz.git. 我认为我能做的是删除abc.git中的所有文件并带回xyz.git。 In terms of code in the following manner. 在代码方面有以下方式。

    • git rm -r * (this is on my abc.git origin) git rm -r *(这是我的abc.git来源)
    • git commit -m git commit -m
    • git push origin master (now abc.git has no files but it has .gitmodules and .git) git push origin master(现在abc.git没有文件,但它有.gitmodules和.git)

    • git remote add xyz git@github.com:xyz.git git remote add xyz git@github.com:xyz.git

    • git checkout -b xyz git checkout -b xyz
    • git pull xyz master git pull xyz master

This is where the conflict starts.. there are 2 types of conflict (external modules, because of some common external modules and some files). 这是冲突开始的地方..有两种类型的冲突(外部模块,因为一些常见的外部模块和一些文件)。

I have thought about a third option which is to just do a git log -l and dump it to a text file and use some viewer to get the history. 我想到了第三个选项,即只需执行git log -l并将其转储到文本文件中,然后使用一些查看器来获取历史记录。

Frankly I just want to save the history best possible way possible, cherry picking is boring but it's do-able. 坦率地说,我只是想尽可能地保存历史,樱桃采摘很无聊,但它是可行的。 Another question is how to save repo logs if you need to delete a repo? 另一个问题是,如果您需要删除回购,如何保存回购日志? Only reason I want to keep a defunct repo alive is for the history and changes. 唯一的理由是我希望保持一个已经废弃的回购活动是为了历史和变化。

Thanks. 谢谢。

I'm totally guessing because it's hard to tell exactly what you are doing from your question. 我完全猜测,因为你很难准确地说出你在做什么。 But my guess is that your remove conflicts with the remote repo's change history. 但我的猜测是你的删除与远程repo的更改历史冲突。 A line gets modified in the remote and deleted in yours. 线路在遥控器中被修改并在您的线路中被删除。 Git doesn't know what to do so it marks it as a conflict. Git不知道该怎么做,所以它把它标记为冲突。

I think your question would be easier to answer if we knew what your goal was. 如果我们知道你的目标是什么,我认为你的问题会更容易回答。

Your edit made it better, but it's stil hard to know just what you want to do. 你的编辑使它变得更好,但很难知道你想做什么。 For example: it's still unclear to me why you want to cherry-pick if xyz is a working (fully functional) evolution over abc. 例如:我仍然不清楚为什么你要挑选,如果xyz是一个有效的(完全功能)进化而不是abc。

If what you want is merge the two repositories so no history is lost, well... just do it. 如果您想要的是合并两个存储库,那么没有历史丢失,那么......就这样做。 You can have two independent branches live there without any stamping on the other's feet. 你可以在那里住两个独立的分支,而不会在另一个脚上留下任何标记。 For example (taking these two because they're on top of github's repo page): 例如(考虑到这两个因为它们位于github的repo页面之上):

$ git clone git://github.com/rails/rails.git monster
$ cd monster
$ git fetch git://github.com/madrobby/scriptaculous.git master:old
$ git branch
    * master
      old
$ ls
    [ looks like rails ]
$ git checkout old
$ ls
    [ looks like scriptaculous ]
$ git checkout master
    [ looks like rails again ]

If what you want is merge the history baselines, ie make xyz a descendent of abc, it's specifically documented in the git filter-branch manual page (search for --parent-filter ), you just want to use your abc "old" branch as a graft point. 如果你想要的是合并历史基线,即使xyz成为abc的后代,它在git filter-branch手册页(搜索--parent-filter )中具体记录,你只想使用你的abc“old”分支作为一个嫁接点。

Talking about graft points, it looks like they might be used directly to do this, but I'm unfamiliar with the concept. 谈到嫁接点,看起来他们可能会直接用它来做这件事,但我对这个概念并不熟悉。 Take a look at this discussion for more details. 请查看此讨论以获取更多详细信息。

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

相关问题 如何删除 git repo 中的所有文件并从本地 git repo 更新/推送? - How can I remove all files in my git repo and update/push from my local git repo? Git - 在 repo 中添加所有新文件 - Git - Add all new files in the repo 当存储库已经非常接近 2GB 时,如何从所有 bitbucket git 历史记录中删除二进制文件? - How to remove binary files from all of the bitbucket git history, when the repo is already very close to 2GB? 如何从NetBeans的Git存储库中删除文件? - How can I remove files from a Git repo in NetBeans? 如何从任何地方添加* all * new / modified文件到git? (比如`git add -A`,或者`git commit -a`用于新文件) - How to add *all* new/modified files to git, from anywhere? (like `git add -A`, or `git commit -a` for new files) 从 git repo 和提交历史中递归删除所有二进制文件 - remove all binary files recursively from git repo and commit history 我添加的所有新文件都被git忽略 - All new files I add are ignored by git 如何从一个 Git 分支中删除文件并将它们添加到新分支 - How can I remove files from one Git branch and add them to a new branch 如何从Git仓库中的所有提交中删除某些文件? - How do you remove certain files from all commits in a Git repo? 如何仅将所有点文件和目录添加到 git 存储库? - How to add only all dot files and directories to a git repo?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM