我的站点

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

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

git小技巧(16)——比较某个文件两次commit的差别

选自stackoverflow

git diff <commit> <commit> filename

例如,比较HEAD和前一个commit之间的差别:

git diff HEAD~1 HEAD filename

git小技巧(15)——显示某个文件的commit历史

选自stackoverflow

git log --follow filename

git小技巧(14)——“git pull” 强行覆盖local repository

参考自stackoverflow

git fetch --all
git reset --hard origin/<branch_name>

git小技巧(13)——git add 总结

选自stackoverflow

Capture

git小技巧(12)——编辑配置文件

通过手动修改配置文件,可以达到很多目的(比如改变upstream):

git config -e

参考自stackoverflow

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

Page 1 of 2

Powered by WordPress & Theme by Anders Norén