Git常用命令笔记

git config --global user.name "your_name"  让提交显示自己的名字

git config --global user.email "your_name@xxx.com"  让提交显示自己的邮箱

ssh-keygen -t rsa -C "your_name@xxx.com"  生成公钥私钥,将公钥给管理员,私钥自己保留。可以一路回车不要密码

git clone git@IP:xxxx.git    从远程服务器上克隆一份代码

git checkout branch_name    切换到某个分支

git status    查看修改添加删除等等的状态

git log    查看commit的日志

git branch -a    查看所有分支

git add xxx    把新文件添加进去

git rm xxx    把不要的文件删除

git commit -a    然后输入提交日志,提交到缓存。如果只修改文件,不添加删除,就直接git commit -a然后git push

git push    把缓存中的文件提交到远程服务器

git format-patch -1 commit号    根据此次commit的哈希值打一个patch,每个patch都会以0001开头,以commit的日志为名称

git format-patch -s -1 commit号    最近的一次commit生成patch

git format-patch commit号    会从这个commit的下一个commit串号开始,打所有commit的patch,前面的数字是增量

git format-patch x...y    会从x到y依次打patch

git format-patch root commit号    会从历史头开始打patch

git am patch_name.patch  将某个patch打进版本库

git grep your_string  查找字符串,字符串中间有空格,用代替

git diff file1 file2  比较两个文件改动前后的差异

git pull  从远程服务器上拉下来文件