Magit简介

官网:https://magit.vc/

用户界面(from magit.vc):

部分命令选项比较多,提供了交互式的popup,不用刻意去记参数。如下图:

常用快捷键及命令

C-x g(magit-status) 开始,查看工作区概况(相当于执行git status)。

快捷键命令描述
smagit-stagegit add xx, 选中指定Untracked files/Unstaged changes
umagit-unstagegit restore xxx, 取消选中
d dmagit-diff-dwimgit diff, 查看光标所处区域diff, 只输入一个d,会看到diff的popup
f umagit-fetch-from-upstreamgit fetch
F umagit-pull-from-upstreamgit pull
c cmagit-commit-creategit commit, C-c C-c提交, C-c C-k取消
b cmagit-branch-creategit switch
m mmagit-merge-plaingit merge
P umagit-push-current-to-upstreamgit push
z zmagit-stash-bothgit stash
z pmagit-stash-popgit stash pop
z kmagit-stash-dropgit stash drop
t tmagit-tag-creategit tag
P Tmagit-push-taggit push origin tag

更多命令可参考:Magit User Manual

其他

GPG Pinentry配置

配置了提交时附上GPG签名,使用Magit后commit输入GPG key密码时,弹窗样式乱掉了。换用pinentry-mac后问题解决。效果如下:

pinentry安装及配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# 提交时使用gpg签名
git config commit.gpgsign true

# 安装pinentry-mac
brew install pinentry-mac

# 指定pinentry程序
echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf

# pinentry-mac配置相关命令
# 查看配置
defaults read org.gpgtools.common

# 取消保存至钥匙串
defaults write org.gpgtools.common UseKeychain NO

# 删除配置
defaults delete org.gpgtools.common

延伸阅读

Visual Magit walk-through

参考文档

https://stackoverflow.com/questions/41502146/git-gpg-onto-mac-osx-error-gpg-failed-to-sign-the-data

https://apple.stackexchange.com/questions/418594/pinentry-mac-disable-keychain-storage