Git

这里记录我容易忘记的Git命令

8. 寻找丢失的commit

checkout或者rebase后,可能会丢失之前的commit,使用git reflog可列出所有提交的commit。

$ git reflog
$ git checkout -b newbranch commit-id

7. long path name on windows

$ git config --system core.longpaths true

6. git sha1

$ echo hello | git hash-object --stdin
ce013625030ba8dba906f756967f9e9ca394464a

$ printf 'blob 6\0hello\n' > test.txt

or

$ echo -en "blob 6\0hello\n" > test.txt

$ openssl sha1 test.txt
SHA1(test.txt)= ce013625030ba8dba906f756967f9e9ca394464a

5. git log

$ 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 fs/           # commits that modify any file under fs/
$ git log -S'foo()'     # commits that add or remove any file data
                        # matching the string 'foo()'
$ git log --no-merges   # dont show merge commits

$ git log --pretty=format:'%h was %an, %ar, message: %s'

$ git log --pretty=format:'%h : %s' --graph

# sort
$ git log --pretty=format:'%h : %s' --topo-order --graph
$ git log --pretty=format:'%h : %s' --date-order --graph

4. 问责

$ git blame filename
$ git blame -L 160,+10 filename

3. 克隆一个裸仓库

$ git clone --bare ~/proj proj.git

2. 更改author信息

$ git commit --amend --author "Author <[email protected]>"

1. Git 配置

# 更改你的编辑器
$ git config --global core.editor vim
# 添加别名
$ git config --global alias.last 'cat-file commit HEAD'
# 添加颜色
$ git config color.branch auto
$ git config color.diff auto
$ git config color.interactive auto
$ git config color.status auto
Or
$ git config color.ui true
# 日志格式
$ git config format.pretty oneline
# 提交者信息
$ git config --global user.name zdd
$ git config --global user.email [email protected]

如果你喜欢这篇文章,欢迎赞赏作者以示鼓励