git Git在两个文件夹之间合并,而不是分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10091858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git merge between two folders, not branches
提问by André Puel
Suppose the following scenario:
假设以下场景:
I have a git project that has a dir named project
. Inside this dir I made some commits.
Then, with cp -r
I duplicated this dir to a dir called project-with-feature-b
, i.e. I manually created a branch.
我有一个 git 项目,它有一个名为project
. 在这个目录中,我做了一些提交。然后,cp -r
我将此目录复制到名为 的目录project-with-feature-b
,即我手动创建了一个分支。
Now I want to merge these two folders like if they were two branches, is there any way to do that using git?
现在我想合并这两个文件夹,就像它们是两个分支一样,有没有办法使用 git 做到这一点?
To be more specific to my problem. I have a svn repository which I am using with git-svn tool to clone it. And I cant use the -T/-b/-t options but I want to make a merge.
更具体地说明我的问题。我有一个 svn 存储库,我正在使用 git-svn 工具来克隆它。我不能使用 -T/-b/-t 选项,但我想进行合并。
回答by nicolsondsouza
This questions is very old, I joined recently.
这个问题很老了,我最近才加入。
I am using ubuntu, and use meld to solve merge issues.
我正在使用 ubuntu,并使用 meld 来解决合并问题。
So If I have 2 folders of the same app, which might have minor changes.
所以如果我有同一个应用程序的 2 个文件夹,它们可能会有细微的变化。
I will do this in the terminal
我将在终端中执行此操作
meld ./app_branch_master ./app_branch_dev
This will open up both the folder, Meld will take time to compare both the folders. It will show you what's there on left hand side and what's on the right hand side. You can also move little code from there.
这将打开两个文件夹,Meld 将花时间比较两个文件夹。它会告诉你左边有什么,右边有什么。您还可以从那里移动少量代码。
That's how I do it.
我就是这样做的。
回答by meagar
Yes, you can technically accomplish this, but only because it is not too late to fix your mistake. You need to go back in time and do this the correct way:
是的,您在技术上可以做到这一点,但这只是因为现在纠正错误还为时不晚。您需要及时返回并以正确的方式执行此操作:
Move your
project-with-feature-b
folder outside your git repo:$ mv project-with-feature-b ..
Go back through
git log
and find the commit ID of the last commit before you created theproject-with-feature-b
directory. If you haven't made any commits "inside" theproject-with-feature-b
directory, you can skip this step.Create a new branch called
feature-b
based on that commit ID. If you skipped step 2, omit<commit-id-from-step-2>
$ git branch feature-b <commit-id-from-step-2> $ git checkout feature-b
In the
feature-b
branch, replace theproject
folder with your backup ofproject-with-feauture-b
$ rm -rf project $ mv ../project-with-feature-b project $ git add project $ git commit -m "Add feature-b"
Go back to your master branch and merge your
feature-b
branch into master$ git merge --no-ff feature-b
将您的
project-with-feature-b
文件夹移到 git 存储库之外:$ mv project-with-feature-b ..
git log
在创建project-with-feature-b
目录之前,返回并找到最后一次提交的提交 ID 。如果您尚未在project-with-feature-b
目录“内部”进行任何提交,则可以跳过此步骤。创建一个
feature-b
基于该提交 ID调用的新分支。如果您跳过了第 2 步,请省略<commit-id-from-step-2>
$ git branch feature-b <commit-id-from-step-2> $ git checkout feature-b
在
feature-b
分支中,project
用您的备份替换文件夹project-with-feauture-b
$ rm -rf project $ mv ../project-with-feature-b project $ git add project $ git commit -m "Add feature-b"
回到你的主分支并将你的
feature-b
分支合并到主分支$ git merge --no-ff feature-b
In the future, you should use branches as above beforeyou start doing work. Learn to use the tools correctly rather than how you thinkthey should work.
以后,你应该在开始工作之前使用上面的分支。学习正确使用这些工具,而不是您认为它们应该如何工作。
回答by KurzedMetal
Take a look at Detach subdirectory into separate Git repository, once you split the history of both directories you'll be able to branch, merge or do whatever you want.
看看Detach subdirectory into separate Git repository,一旦你拆分了两个目录的历史,你就可以分支、合并或做任何你想做的事。