Android系统开发工程师,非连续的记录工作中用到的git命令:
1. 设置user.name,user.email,信息将显示在提交log中
例如:user.name=leo.wang user.email=leo.wang@gmail.com
git config --global user.name leo.wang
git config --global user.email leo.wang@gmail.com
信息保存在~/.gitconfig文件,使用命令git config -l 查看信息
2. 修改本地提交中user.name和user,email
第一点的基础上,执行git commit --amend --reset-author
3. 设置客户端账户信息
某些时候,需要在客户端的ssh中添加git账户信息。有手动方式和自动方式,这里介绍一种自动方式
git config --global url.ssh://username@120.25.200.39:29418.insteadof ssh://120.25.200.39
->当输入为ssh://120.25.200.39 会自动替换为ssh://username@120.25.200.39:29418
在~./gitconfig文件中,可以保存多条url规则(user.name/user.email就只能保存一条)
4. 生成patch
git format-patch -[n] commit_num
备注:-n的n值是一个合理范围的阿拉伯数字。例如,从commit_num开始的n个提交生成patch(包括commit_num)
5. 自动打patch
git包含自动打patch的命令,但觉得不好用。自己常用linux patch
patch -p[0] < XXX.patch
-p是指路径,其后的数字表示去掉patch文件中的前几级目录。0表示不去掉,使用全路径
6 show commit log查看类命令
git log <--显示已经commit的log信息
git log --stat <--显示已经commit的log信息,log信息中包含文件列表
git show <--查看cmmit的修改内容
7. commit类命令
git branch <new_branch> <--命令创建new branch,但不checkout该分支(分支前带*表示当前分支)
git checkout <new_branch> <--命令切换到new branch
git checkout -b <new_branch> <--命令创建new branch,同时切换到new branch
git diff <--查看文件变更处
git add/rm <--增加修改文件/删除文件
git commit -m "<message_log>" <--提交到本地,用git log可以看到记录
git reset --hard <commit_num> <--本地提交被回退,文件修改被还原,commit tree 相关节点被清除