简体   繁体   中英

How to merge two directories into same branch using git

I want to merge two directories in the same branch.

I know git rules as if there is any required featured to add. I should have created a another another branch. and then i have to merge that branch into some another branch,

This is my current directory structure

App- 
    directory - 1
    directory - 2

How to merge these two directories into one. I have already seen many questions related, But nothing worked

Without creating new branch

If there is another method to do this. Please suggest

I assume, that all your changes have been committed and that your branch with both directories is called both-directories .

This approach will loose all your git commit history for directory - 2 and squash them into one commit. If you want to keep that commit history you have to modify step 1-5 for every commit before continuing with step 6.

  1. Copy the files from directory - 2 to a folder outside of git. Lets call that folder outside-directory-2
  2. Find the commit that introduced directory - 2 and start a new branch from its ancestor. Call this branch something like directory2 .
  3. Check out the branch directory2 .
  4. Copy all contents from outside-directory-2 to your directory - 1 folder.
  5. Commit these changes to the directory2 branch.
  6. Check out the branch both-directories .
  7. Merge the branch directory2
  8. delete the folder directory - 2 and commit these changes.
  9. Now your branch both-directories contains all changes from directory - 1 and directory - 2 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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