git作为分布式管理代码的工具,已经在各个公司非常成熟了,这东西不经常使用的话,难免会把命令、运行机制忘掉。在这里简单记录一下git常用操作命令。
Git常用操作
.gitconfig文件配置名字和邮箱或者配置用户名和email, 此时$HOME目录会创建一个.gitconfig文件:
1
2git config --global user.name "gaojianchao"
git config --global user.email "xxx@domain.com"github账号添加ssh keys,方便远程管理仓库:
1
ssh-keygen -t rsa -C "xxx@domain.com"
打开id_rsa.pub文件,复制到github账号管理的SSH KEY界面中:
配置.gitconfig命令alias,方便快捷使用命令:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25git config --global alias.lgf "log --color --graph -- pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"
git config --global alias.xx
st = status
ci = commit -a
df = diff
co = checkout
br = branch
rb = rebase
l = log --oneline --decorate -12 --color
ll = log --oneline --decorate --color
lc = log --graph --color
dci = dcommit
s = submodule
sbi = submodule init
sbu = submodule update
sf = submodule foreach
sbp = submodule foreach git pull
sbc = submodule foreach git co master
; rb = svn rebase
spush = push --recurse-submodules=on-demand
supdate = submodule update --remote --merge
pl = pull
ps = push
lg = log --graph --pretty=oneline --abbrev-commit
lgf = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --git管理代码常用命令:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18git add -A
git commit -m ""
git push origin master
git pull
git lgf
git remote -v
git branch -a
git checkout branch
git checkout -- .
git diff master --stat
git merge master
git mergetool:
:diffg RE
:diffg BA
:diffg LO
git reset --hard id
git push -f -u origin master
git co -p branch filename