Custom Search

Wednesday, January 15, 2014

Git How to move all commits to another repository using git format-patch and git am

1)
Goto Project folder. Your first repo
#cd /home/saju/project1/src

2)
Take diffs
#git format-patch -o /home/saju/patch_backup/ 0aa25e5ce31ab05db98d258f90850f478303dc23~..699a6a0decd6889b7cfbfc6fc80ab641965385b4

3)
Goto your new second repo
#/home/saju/project2/src



4)
Creaet git repo, if not there
#git init
#git add *
#git commit -m "create new git repo: initial commit"

5)
Apply patch
#git am --reject /home/saju/patch_backup/0001-Migration-to-Django-1.5-Initial-Commit.patch

6)
Check for rejected files
#find . -name "*.rej"

7)
Some checks (Optional)
#git diff
#git log

8)
If patch failed, then we have to add all chaged file and run "git am --resolved"
#git add -A
#git diff
#If there any conflict, fix that, then
#git am --resolved
#git log

9)
Delted all rejected filed "*.rej" and apply the next patch (Step-5)
#find . -name '*.rej' -exec rm {} \;

1 comment:

  1. 1)
    In repo-1, take copy of last two commits with commit message

    a)
    $git log -n 2

    b)
    $ git format-patch -o /home/saju/puppet_push_work/pp/c1 29385651d5fbee7b2924d2b6f148fd90f34023a5~..5857daf47530488e4b4dd36cb524bf9395486d69
    /home/saju/puppet_push_work/pp/c1/0001-Don-t-allow-member-to-update-internal-virtual-networ.patch
    /home/saju/puppet_push_work/pp/c1/0002-Added-rule-to-policy.json.patch

    2)
    In repo-2, Apply copied commits to repo-2 with commit message

    a)
    $ git am --reject /home/saju/puppet_push_work/pp/c1/0001-Don-t-allow-member-to-update-internal-virtual-networ.patch
    Applying: Don't allow member to update internal virtual network and make it external.
    Checking patch files/policy.json...
    Checking patch manifests/init.pp...
    Applied patch files/policy.json cleanly.
    Applied patch manifests/init.pp cleanly.


    b)
    $ git am --reject /home/saju/puppet_push_work/pp/c1/0002-Added-rule-to-policy.json.patchApplying: Added rule to policy.json
    Checking patch files/policy.json...
    Applied patch files/policy.json cleanly.

    ReplyDelete