Git 基础培训



  • PowerPoint的演示我用得太少。我借了一个投影仪,用了复制模式。按理说我笔记本的屏幕应该和幕布应该显示同样的内容,但是,PowerPoint在播放的时候在笔记本上显示的演讲者模式,幕布上就用不一样的分辨率显示观众内容。这个是我始料未及的。由于分辨率的改变导致观众内容非常模糊,所以在前半部分根本在和银幕做斗争。后来,我干脆不播放PPT,直接在Bash窗口里打我的命令,效果反而好些。
  • 准备的东西有点儿多,进程也编排得有点花哨。忽略了受众是常年用SVN,对分布式版本控制完全没有概念的。解释起来有一定的难度。应该拆成两个培训,可能效果会好一些。
  • 下次如果有机会再做这类的培训,我会选择Jupyter Notebook来做演示;或者写扁平风格的PPT来做,不要动画效果,朴实一些。



Centralized VCS: designed with the intent that there is One True Source that is Blessed, and therefore Good.

Distributed VCS: systems are designed with the intent that one repository is as good as any other.

1 Git

Since 2005 created by Linus Torvalds


Linux: apt-get install git
Windows: Git for Windows(Git Bash)/TortoiseGit/SourceTree

Basic configurations

git config –global “Your name”
git config –global
git config –global color.ui true


Basic Commands

  • init
  • add
  • commit
  • status
  • log
  • diff
  • show
  • mv
  • rm
  • reset

Branch Related Commands

  • branch
  • checkout
  • merge
  • rebase

Collaborating Commands

  • clone
  • fetch
  • push
  • pull

2 Basic Workflow

Like SVN

  • git init
  • git status
  • git add
  • git commit
  • git log
  • git diff
  • git tag


  • git branch
  • git checkout –b xxx
  • git merge xxx


  • git stash
  • git stash apply
  • git stash pop
  • git stash drop
  • git stash list

3 Collaborating with Other Colleagues

GitLab or GitHub

Creating Repositories

Cloning others’ Repository

Collaborating Commands

4 Other Tips

I am so sorry that I have done these…

  • git checkout — files
  • git reset –hard/–soft

I can ignore the conflicts, using mine…

  • git checkout –ours/–theirs

I need one node, instead of whole branch

  • git cherry-pick

What have I done in this repo?

  • git reflog

Comprehensive logs

  • git log v2.5.. # commits since (not reachable from) v2.5
  • git log test..master # commits reachable from master but not test
  • git log master..test # commits reachable from test but not master
  • git log master…test # commits reachable from either test or master, but not both
  • git log –since=”2 weeks ago” # commits from the last 2 weeks
  • git log Makefile # commits that modify Makefile
  • git log –no-merges # dont show merge commit


电子邮件地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.