Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git merge between two folders, not branches

Tags:

git

merge

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.

Now I want to merge these two folders like if they were two branches, is there any way to do that using 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.

like image 682
André Puel Avatar asked Apr 10 '12 15:04

André Puel


3 Answers

This questions is very old, I joined recently.

I am using ubuntu, and use meld to solve merge issues.

So If I have 2 folders of the same app, which might have minor changes.

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.

That's how I do it.

like image 151
nicolsondsouza Avatar answered Sep 19 '22 22:09

nicolsondsouza


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:

  1. Move your project-with-feature-b folder outside your git repo:

    $ mv project-with-feature-b ..
    
  2. Go back through git log and find the commit ID of the last commit before you created the project-with-feature-b directory. If you haven't made any commits "inside" the project-with-feature-b directory, you can skip this step.

  3. 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
    
  4. In the feature-b branch, replace the project folder with your backup of project-with-feauture-b

    $ rm -rf project
    $ mv ../project-with-feature-b project
    $ git add project
    $ git commit -m "Add feature-b"
    
  5. Go back to your master branch and merge your feature-b branch into master

    $ git merge --no-ff feature-b
    

In the future, you should use branches as above before you start doing work. Learn to use the tools correctly rather than how you think they should work.

like image 42
meagar Avatar answered Sep 20 '22 22:09

meagar


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.

like image 43
KurzedMetal Avatar answered Sep 22 '22 22:09

KurzedMetal