git show

  1. Show the file changes for a commit : git show --stat $commit_num

git log

  1. show logs between two tags: git log kernel-3.10.0-54.el7..kernel-3.10.0-59.el7

git diff

  1. Show git diff even after git add : git diff --staged
  2. git diff > some.patch or git diff master > some.patch

git add

  1. Use git add -p to split a file

git commit

  1. edit the last commit : git commit --amend
  2. commit seperate line for a file
    1. git add –patch
    2. git commit

git blame

show the commit by each line

  1. git blame -L 660,680 net/ipv4/ip_sockglue.c

git patch

  1. git format-patch -1
  2. git format-patch -1 –subject-prefix=[Patch v2
  3. git format-patch -2 –cover-letter: add patch[0/n] for a short description
  4. format a merge commit: git log -p –pretty=email –stat -m –first-parent origin/master..HEAD > feature.patch

git describe

  1. Show the tag which commit belong to: git describe $commit_id

git branch

git remote add net git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git git remote update git branch -a git checkout -b net remotes/net/master

git tag

  1. How to list the last tags git for-each-ref --format="%(taggerdate): %(refname)" --sort=-taggerdate --count=10 refs/tags
  2. How to delete a tag $ git tag | grep tag-name $ git tag -d tag-name

$ make tag rhts-mk-tag-release Error: current tag udp-Performance-1_0-2 is not an ancestor of HEAD (Hint: make sure it is merged into this branch) make: *** [tag] Error 1 $ git tag udp-Performance-1_0-3 -m udp-Performance-1_0-3

git reabse

  1. git branch network; git rebase master
  2. Edit a commit which have not pushed: git commit first, then git rebase -i $commit^, then mv the commit down to the commit you want to change, and set f.

Git Clone

$ git clone –reference /local-path git://git.repo /new-local-path $ git repack -a

Git create repo

  1. Create a empty repo $ mkdir my-repo.git && cd my-repo.git $ git –bare init
  2. Clone another git repo $ git clone –bare $URL $ git remote add –mirror origin $URL $ git fetch
  3. setup git daemon $ yum install -y git-daemon $ git daemon –verbose –export-all –base-path=/home/git –reuseaddr –enable=receive-pack to enable git archive –remote, add the following in the repo.git/config [daemon] uploadarch = true

Git merge and read-tree

Merge repoA into repoB

  1. Add remote repoA and fetch to local $ git remote add -f repoA path_to_repoA
  2. Run a merge but not commit the result, also need to specify the merge strategy ours with the -s switch. $ git merge -s ours --no-commit repoA/master
  3. read in the tree from the remote, taking care to provide a subdirectory into which the subproject will go. $ git read-tree --prefix=other/path/you/want/ -u projectA/master
  4. commit the change $ git commit
  5. As this is a merge, we cant use git pull --reabse to update. use git pull and then git push directly

Ref: https://help.github.com/articles/working-with-subtree-merge

Ref: http://randyfay.com/node/93