Git repository Merge (Add a new repository to the original git repository)

Source: Internet
Author: User
Tags tmp folder

I often write essays. It is very convenient to participate in version control. Sometimes, due to various reasons (such as network failure), I cannot clone them to the local machine, and I want to write new essays, there will be a lot of submission history in the write process. When I merge it into the casual folder, I also want to submit the history.

Now we can simulate this scenario:

 
1. Create the essays folder and add essay1.md; 2. Create the TMP folder, add the essays2.md folder, add the content, and submit the file multiple times;

Now the problem is that I don't just want something under the TMP folder, but I also want it to submit history;

The procedure is as follows:

 
1. Go to the essays folder, add the remote branch, and add git remote TMP .. /tmp/2. Capture remote branch data to the local repository: git fetch tmp3, generate a temporary new branch: git checkout-B TMP tmp/master4, and switch back to the master Branch: git checkout master5. Merge the temporary new branch to the master branch: git merge TMP 6. Delete the temporary branch: git branch-D TMP

The effect after merging is as follows:

For ease of use, I have compiled a Python script,CodeAs follows (gitreposmerge. py ):

 #  ! /Usr/bin/Python  Import  Osdir1 ="  Essays  "  Dir2 = "  ../Tmp  "  Tmpbranchname = "  TMP  "  Execcommand = OS. systemstrcmd1 = " Cd % S & git remote add % S & git fetch % s \ & git checkout-B % S/Master & git checkout master \ & git merge % S & git branch-D % S & CD ..  " % (Dir1, tmpbranchname, dir2, \ tmpbranchname ,)  Print  Str1_1execcommand (strcmd1) 

 

The Code uses the following directory structure:

That is, the script and git repository are in the same directory.

Run the gitreposmerge. py script.

GIST link: https://gist.github.com/mike-zhang/5597980 in this example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.