1. '''
  2. 1.常用
  3. '''
  4. $ git remote add origin git@github.com:yeszao/dofiler.git # 配置远程git版本库
  5. $ git pull origin master # 下载代码及快速合并
  6. $ git push origin master # 上传代码及快速合并
  7. $ git fetch origin # 从远程库获取代码
  8. $ git branch # 显示所有分支
  9. $ git checkout master # 切换到master分支
  10. $ git checkout -b dev # 创建并切换到dev分支
  11. $ git commit -m "first version" # 提交
  12. $ git status # 查看状态
  13. $ git log # 查看提交历史
  14. $ git config --global core.editor vim # 设置默认编辑器为vim(git默认用nano)
  15. $ git config core.ignorecase false # 设置大小写敏感
  16. $ git config --global user.name "YOUR NAME" # 设置用户名
  17. $ git config --global user.email "YOUR EMAIL ADDRESS" # 设置邮箱
  18. '''
  19. 2.修改与提交
  20. '''
  21. $ git status # 查看状态
  22. $ git diff # 查看变更内容
  23. $ git add . # 跟踪所有改动过的文件
  24. git add --all # 同上
  25. $ git add <file> # 跟踪指定的文件
  26. $ git mv <old> <new> # 文件改名
  27. $ git rm <file> # 删除文件
  28. $ git rm --cached <file> # 停止跟踪文件但不删除
  29. $ git commit -m “commit message” # 提交所有更新过的文件
  30. $ git commit --amend # 修改最后一次提交
  31. '''
  32. 3.查看提交历史
  33. '''
  34. $ git log # 查看提交历史
  35. $ git log -p <file> # 查看指定文件的提交历史
  36. $ git reflog # 查看比较全的历史,包括版本回退等
  37. $ git blame <file> # 以列表方式查看指定文件的提交历史
  38. '''
  39. 4.版本回退 # HEAD 是一个特别指针。在 git 中,它是一个指向你正在工作中的本地分支的指针,可以将 HEAD 想象为当前分支的别名。
  40. '''
  41. $ git reset --hard HEAD^ # 回退到上一个版本
  42. $ git reset --hard HEAD # 撤消工作目录中所有未提交文件的修改内容
  43. $ git reset --hard <version> # 撤销到某个特定版本
  44. $ git checkout HEAD <file> # 撤消指定的未提交文件的修改内容
  45. $ git checkout -- <file> # 同上一个命令
  46. $ git revert <commit> # 撤消指定的提交
  47. '''
  48. 5.stash
  49. '''
  50. $ git stash # 暂时储存当前的更改
  51. $ git stash list # 显示暂存列表list
  52. $ git stash apply # 应用最新的暂存区的更改
  53. $ git stash pop # 应用最新的暂存区的更改,并删除最新暂存区
  54. '''
  55. 6.rebase
  56. '''
  57. $ git stash # 暂时储存当前的更改
  58. $ git stash list # 显示暂存列表list
  59. $ git stash apply # 应用最新的暂存区的更改
  60. $ git stash pop # 应用最新的暂存区的更改,并删除最新暂存区
  61. '''
  62. 6.merge
  63. '''
  64. $ git cherry-pick <commit> # 只合并某次commit
  65. 7、强制pull
  66. $ git fetch --all
  67. $ git reset --hard origin/master
  68. $ git pull

Command line instructions

Git global setup

git config —global user.name “renxinlei”
git config —global user.email “renxinlei@sensetime.com”

Create a new repository

git clone git@gitlab.bj.sensetime.com:renxinlei/OSS.git
cd OSS
touch README.md
git add README.md
git commit -m “add README”
git push -u origin master

Existing folder

cd existing_folder
git init
git remote add origin git@gitlab.bj.sensetime.com:renxinlei/OSS.git
git add .
git commit -m “Initial commit”
git push -u origin master

Existing Git repository

cd existing_repo
git remote add origin git@gitlab.bj.sensetime.com:renxinlei/OSS.git
git push -u origin —all
git push -u origin —tags

1.设置基本信息

git config —global user.name “shuxin.yang”
git config —global user.email “shuxin.yang@zhangmen.com“

删除基本信息

git config —global —unset user.name “shuxin.yang”
git config —global —unset user.email “shuxin.yang@zhangmen.com“

2.生成ssh key

ssh-keygen -t rsa -C “shuxin.yang@zhangmen.com“

3.将id_rsa.pub中的值copy到gitlab的ssh key中

4.clone代码到本地

git clone ssh://git@zmgitlab.zmlearn.com:10022/rec/pangoo.git

5.拉取master的最新代码到本地

git pull origin master

常用命令

git config —list # 查看设置的用户信息
git checkout -b dev_shuxin # 到一个新的分支
git dev_shuxin # 查看自己分支
git diff # 查看版本之间代码差别
vim diff # 查看两个文件间代码差别

git remote -v # 查看远程分支url
git remote rm origin # 删除旧的远程分支
git remote add origin [url] # 添加新的远程分支

git branch kg_dev_shuxin # 创建本地分支
git branch —delete kg_dev_shuxin # 删除本地分支
git branch # 查看本地分支
git branch -a # 查看远程分支
git push origin :<远程端分支> # 在github远程端删除一个分支

git log # 查看commit-id
git reset —hard commit-id # 代码回滚到commit-id,将commit-id之后提交的commit都去除
git reset —hard HEAD~3 # 将最近3次的提交回滚

git branch -r —merged 查看已经merged的分支
git branch -D 删除分支
git push origin —delete xxxx 删除远程分支
git branch -r —sort=-committerdate 按最近提交倒序排
git fetch -p 远程分支没了,但是本地还有,可以用此命令
grep -v 排除
sed ‘s/origin///g’ 字符串替换 origin 为 空,其中 s 代表替换

~/branch.txt 输出到文件 xargs 将标准输入数据转换成命令行

6.删除远程仓库中的文件(本地文件不删除)

git rm -r —cached 【your file folder】

if you already have code ready to be pushed to this repository then run this in your terminal.

cd existing-project
git init
git add —all
git commit -m “Initial Commit”
git remote add origin ssh://git@git.sankuai.com/~renxinlei02/git-share.git
git push origin master

If your code is already tracked by Git then set this repository as your “origin” to push to.

cd existing-project
git remote set-url origin ssh://git@git.sankuai.com/~renxinlei02/git-share.git
git push origin master