git: How to find merge commit which include a specific commit

git-whence tool can help to easily find merge commit which include given commit.

# gem install git-whence
# git-whence 6d37485
Merge pull request #10486 from foo/bar

Reference:

Advertisements

Mirror external repository on github

If we want to fork repository from any github repository, it is possible through github fork utility. However if we want to get some external repository with all branches, tags and commit history, following steps can be useful:

    1. Create an empty repository on github
      • Go to https://github.com/new
      • Provide repository name, access type
      • Click on “Create repository” button
    2. Clone remote repository (original one on your local system using below command:
      git clone --mirror <git-repo>
      e.g.
      git clone --miror https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
    3. Go to cloned repository directory and push all refs to your empty repository
      cd <remote-git-directory>
      git push --mirror <your-empty-repo>
      e.g.
      cd linux.git
      git push --mirror https://github.com/rajanvaja/linux/

 

Update forked repo with remote repo

Auto merge

Add remote repository

# cd <forked-repo>
# git checkout 
# git remote add upstream <upstream-repo-git-link>
#git fetch upstream

Updating fork from remote repo

# git pull upstream <upstream-branch>

Example (This is what I did to sync from remote branch and push to forked repo)

# cd <forked-repo>
# git checkout
# git remote add upstream <upstream-repo-git-link>
# git fetch upstream
# git pull upstream master --rebase

As local repo changes are rebased, faced error while pushing changes to forked repo. Runt these commands to rebase changes for forked branch.

# git pull --rebase
# git push origin <forked-remote-branch>

 

Force Update

If normal merge doesn’t wok and you are ready to do force update of your forked repo branch with original repo branch:

#git remote add upstream <upstream-repo-git-link>
# git fetch upstream
# git checkout <upstream branch>
# git reset --hard upstream/<upstream-branch>  
# git push origin <forked-remote-branch> --force 

 

Git send email

My git send-email config:

git config sendemail.smtpuser 
git config sendemail.smtpserver smtp.googlemail.com
git config sendemail.smtpencryption tls
git config sendemail.smtpserverport 587
git config sendemail.suppresscc self
git send-email --to <to_list> --in-reply-to="<message_id_of_message1>" --thread *.patch

This will generate patch in below way:
– Message 1
.           – Patch 1
.                       – Patch 2

This is how I prepared cover page followed by two patches:

git format-patch -2 --subject-prefix="PATCH v2" --cover-letter --thread=shallow
  • Here –cover-later would create a cover page. We need to modify subject and content.
  • The –thread=shallow flag specifies that all patches will be In-Reply-To your cover letter. Hence all patches would be in reply to cover page by default.
  • –subject-prefix=”PATCH v2″ would use given prefix in patch file.

This is how I sent this patches:

git send-email –to <to_id> –cc <cc_id> <patches>

The patch follows below sequence

  • Cover Page
    • Patch 1
    • Patch 2

References:
https://burzalodowa.wordpress.com/2013/10/05/how-to-send-patches-with-git-send-email/
http://git-scm.com/docs/git-send-email
example patch

Git useful commands

  • Git reset hard remote branch to specific commit
    # git reset --hard <commit-id>
    # git push -f origin <branch_name>
    
  • Add prefix in patch subject
    # git format-patch --subject-prefix=PREFIX][PATCH
    
      This will generate a patch with subject: [PREFIX] [PATCH]
  • Get list of new added files between two commits
    # git diff --name-only --diff-filter=A <old-commit-id> <new-commit-id>
  • Get list of modified files between two commits
    # git diff --name-only --diff-filter=M <old-commit-id> <new-commit-id>