我的站点

一个系统软件工程师的随手涂鸦

Category: git小技巧 (Page 1 of 2)

git小技巧(11)——如何checkout一个remote branch

参考自Stackoverflow

git checkout -b <BRANCH-NAME> <REMOTE-NAME>/<BRANCH-NAME>

git小技巧(10)——如何同original master进行rebase

original repositorymaster branch rebase的方法:
(1)

git fetch origin # Updates origin/master
git rebase origin/master # Rebases current branch onto origin/master

(2)

git pull --rebase origin master

参考资料:
How to rebase local branch with remote master

git小技巧(9)——避免提交时每次输入用户名和密码

避免每次提交改动时输入用户名和密码,可以使用下列命令:

$ git config credential.helper store
$ git push https://github.com/username/repo.git

参考资料:
Git push: username, password, how to avoid?

git小技巧(8)——“git checkout – ”

git checkout -切换到之前工作的branch。请看例子:

[root@localhost debugging-stories]# git branch
  master
  patch-1
* patch-2
[root@localhost debugging-stories]# git checkout -
Switched to branch 'patch-1'
[root@localhost debugging-stories]# git branch
  master
* patch-1
  patch-2

可以看到切换到了patch-1 branch

 

git小技巧(7)——“git format-patch ..

git format-patch <rev1>..<rev2>会产生两个commit之间的patch<rev>commit ID)。请看例子:

[root@localhost linux]# git format-patch 9f10e5bf62f7b9937afeee8ff0a491f87438e2a2..571dbbd4d044e11c78bc077acb3ccef4c77b096e
0001-iommu-vt-d-Init-QI-before-root-entry-is-allocated.patch
0002-iommu-vt-d-Make-root-entry-visible-for-hardware-righ.patch
0003-iommu-vt-d-Detect-pre-enabled-translation.patch
0004-iommu-vt-d-Copy-translation-tables-from-old-kernel.patch
0005-iommu-vt-d-Do-not-re-use-domain-ids-from-the-old-ker.patch
0006-iommu-vt-d-Mark-copied-context-entries.patch
0007-iommu-vt-d-Allocate-si_domain-in-init_dmars.patch
0008-iommu-vt-d-Don-t-do-early-domain-assignment-if-kdump.patch
0009-iommu-vt-d-Don-t-copy-translation-tables-if-RTT-bit-.patch
0010-iommu-vt-d-Don-t-disable-translation-prior-to-OS-han.patch
0011-iommu-vt-d-Enable-Translation-only-if-it-was-previou.patch
0012-iommu-vt-d-Move-EIM-detection-to-intel_prepare_irq_r.patch
0013-iommu-vt-d-Move-QI-initializationt-to-intel_setup_ir.patch
0014-iommu-vt-d-Disable-IRQ-remapping-in-intel_prepare_ir.patch
0015-iommu-vt-d-Set-IRTA-in-intel_setup_irq_remapping.patch
0016-iommu-vt-d-Copy-IR-table-from-old-kernel-when-in-kdu.patch
0017-iommu-vt-d-Make-sure-copied-over-IR-entries-are-not-.patch
0018-iommu-vt-d-Don-t-disable-IR-when-it-was-previously-e.patch

但是这个命令不会包含<rev1>这个commit产生的patch。要想包含<rev1>这个commit产生的patch,需要在<rev1>后加上~,代表<rev1>之前的commit。请看例子:

[root@localhost linux]# git format-patch 9f10e5bf62f7b9937afeee8ff0a491f87438e2a2~..571dbbd4d044e11c78bc077acb3ccef4c77b096e
0001-iommu-vt-d-Cleanup-log-messages.patch
0002-iommu-vt-d-Init-QI-before-root-entry-is-allocated.patch
0003-iommu-vt-d-Make-root-entry-visible-for-hardware-righ.patch
0004-iommu-vt-d-Detect-pre-enabled-translation.patch
0005-iommu-vt-d-Copy-translation-tables-from-old-kernel.patch
0006-iommu-vt-d-Do-not-re-use-domain-ids-from-the-old-ker.patch
0007-iommu-vt-d-Mark-copied-context-entries.patch
0008-iommu-vt-d-Allocate-si_domain-in-init_dmars.patch
0009-iommu-vt-d-Don-t-do-early-domain-assignment-if-kdump.patch
0010-iommu-vt-d-Don-t-copy-translation-tables-if-RTT-bit-.patch
0011-iommu-vt-d-Don-t-disable-translation-prior-to-OS-han.patch
0012-iommu-vt-d-Enable-Translation-only-if-it-was-previou.patch
0013-iommu-vt-d-Move-EIM-detection-to-intel_prepare_irq_r.patch
0014-iommu-vt-d-Move-QI-initializationt-to-intel_setup_ir.patch
0015-iommu-vt-d-Disable-IRQ-remapping-in-intel_prepare_ir.patch
0016-iommu-vt-d-Set-IRTA-in-intel_setup_irq_remapping.patch
0017-iommu-vt-d-Copy-IR-table-from-old-kernel-when-in-kdu.patch
0018-iommu-vt-d-Make-sure-copied-over-IR-entries-are-not-.patch
0019-iommu-vt-d-Don-t-disable-IR-when-it-was-previously-e.patch

可以看到多产生了一个patch

git小技巧(6)——“git branch -m

git branch -m <oldname> <newname>可以把branch重命名。例如:

[root@localhost test_git]# git branch
  master
* new
[root@localhost test_git]# git branch -m new new1
[root@localhost test_git]# git branch
  master
* new1

如果要重命名的就是当前branch,可以省略<oldname>

[root@localhost test_git]# git branch -m new2
[root@localhost test_git]# git branch
  master
* new2

git小技巧(5)——“git checkout -b

git checkout -b <branch>"创建一个新的branch,并且切换到这个branch上。例如:

[root@localhost git_repo]# git checkout -b new-branch
Switched to a new branch 'new-branch'
[root@localhost git_repo]# git branch
  master
* new-branch

git小技巧(4)——“git commit -a -m

git commit -a -m "<message>"可以stage所有已经tracked的文件,然后一并commit"<message>"会作为commit的日志。例如:

[root@localhost git_repo]# git commit -a -m "Make a REAL rainbow"
[crazy-alt 4f00399] Make a REAL rainbow

git小技巧(3)——“git branch -D

git branch -D <branch-name>可以强行删除没有merge的分支。需要注意的是这个分支的内容无法恢复。例如:

[root@localhost git_repo]# git branch -D crazy-alt
Deleted branch crazy-alt (was 4f00399).

git小技巧(2)——“git commit -m”

git commit -m可以直接在命令行输入commit message,而不用打开编辑器输入了。例如:

[root@localhost git_repo]# git commit -m "Add new links"

Page 1 of 2

Powered by WordPress & Theme by Anders Norén