Git tips
Contents
git show
- Show the file changes for a commit :
git show --stat $commit_num
git log
- show logs between two tags:
git log kernel-3.10.0-54.el7..kernel-3.10.0-59.el7
git diff
- Show
git diff
even aftergit add
:git diff --staged
git diff > some.patch
orgit diff master > some.patch
git add
- Use
git add -p
to split a file
git commit
- edit the last commit :
git commit --amend
- commit seperate line for a file
- git add –patch
- git commit
git blame
show the commit by each line
- git blame -L 660,680 net/ipv4/ip_sockglue.c
git patch
- git format-patch -1
- git format-patch -1 –subject-prefix=[Patch v2
- git format-patch -2 –cover-letter: add patch[0/n] for a short description
- format a merge commit: git log -p –pretty=email –stat -m –first-parent origin/master..HEAD > feature.patch
git describe
- 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
- How to list the last tags
git for-each-ref --format="%(taggerdate): %(refname)" --sort=-taggerdate --count=10 refs/tags
- 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
- git branch network; git rebase master
- 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
- Create a empty repo $ mkdir my-repo.git && cd my-repo.git $ git –bare init
- Clone another git repo $ git clone –bare $URL $ git remote add –mirror origin $URL $ git fetch
- 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
- Add remote repoA and fetch to local
$ git remote add -f repoA path_to_repoA
- 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
- 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
- commit the change
$ git commit
- As this is a merge, we cant use
git pull --reabse
to update. usegit pull
and thengit push
directly
Ref: https://help.github.com/articles/working-with-subtree-merge
Author Hangbin Liu
LastMod 2018-12-13 (1672b97)