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