GIT 常用命令

来源:互联网 发布:随机密码生成算法 编辑:程序博客网 时间:2024/06/16 21:38

GIT 常用命令

git 
参考:码云 - Git OSChina、Git使用说明 
- 配置Git

  1. git config --global user.name "Your Name"
  2. git config --global user.email "email@example.com"
  3. git config --global http.proxy http://127.0.0.1:8088 配置代理
  4. git config --global credential.helper store 免输密码
  • 创建SSH Key
  1. ssh-keygen -t rsa -C "youremail@example.com"
  • 远程添加-关联仓库、删除远程仓库
  1. git remote add origin git@git.oschina.net:lvmq/m2.git
  2. git remote add origin https://git.oschina.net/lvmq/m2.git
  3. git remote remove (branch name) 取消远程仓库的关联
  4. git push -u origin master 第一次提交代码至远程仓库需要用 -u参数
  5. git push origin --delete serverfix 删除远程serverfix分支
  6. If you already have a file checked in, and you want to ignore it, Git will not ignore the file if you add a rule later. In those cases, you must untrack the file first, by running the following command in your terminal:
  7. git rm --cached readme.txt 删除版本管理文件,忽略不必要的管理文件
  8. git rm --cached FILENAME 忽略文件的变动,不提交,相当于先从版本控制中删除,再加入ignore file
  • 删除版本管理文件,忽略不必要的管理文件
  1. If you already have a file checked in, and you want to ignore it, Git will not ignore the file if you add a rule later. In those cases, you must untrack the file first, by running the following command in your terminal:
  2. git rm --cached FILENAME 忽略文件的变动,不提交,相当于先从版本控制中删除,再加入ignore file
  • Git 代码常用命令
  1. git init 在指定目录下,使其成为一个repository
  2. rm -rf .git 指定目录下,删除.git文件,取消repository
  3. git clone https://**/zhongche.git Clone远程仓库
  4. git status 查看文件当前状态
  5. git add readme.txt
  6. git add 一次命令只添加一个文件 用*代替可多个
  7. git update-index --assume-unchanged PATH PATH处输入要忽略的文件
  8. git commit -m "write some messages"
  9. git commit 一次提交前NAdd的文件
  10. git diff readme.txt 查看文件改动的地方
  11. git checkout (--) readme.txt 放弃修改或删除 改动会被回滚
  12. git log (--pretty=oneline)查看提交历史
  13. git reflog 查看历史操作命令
  14. cat filename 查看文件内容
  15. git reset --hard commitId 回退到某一版本并且放弃所有的修改
  16. git reset commitId 回退到某一版本但保存自该版本起的修改
  17. git commit --amend 修改最后一次提交的信息描述
  18. git push origin master 与远程代码同步
  • Git 分支管理
  1. git checkout -b dev 创建并切换至新的分支
  2. git branch dev 创建dev分支
  3. git checkout dev 切换分支
  4. git branch 查看分支情况
  5. git merge dev dev分支合并到当前分支
  6. git merge --no-ff -m "merge with no-ff" dev 普通模式合并 可查看合并历史记录
  7. git branch -d dev删除dev 分支
  8. git branch -D feature-vulcan 合并失败后 强制删除分支
  9. git Merge保存后有冲突 先手工处理 然后重新AddCommit一次 提交处理冲突
  10. git log --graph --pretty=oneline --abbrev-commit 查看分支合并情况
  • Git stash 保存分支
  1. git stash 保存现场工作
  2. git stash list 查看保存现场的记录
  3. git stash pop 恢复现场
  • Git 多人协作
  1. git remote 查看远程库情况
  2. git remote -v 查看远程库详细信息
  • Git 标签
  1. 命令git tag <name> 用于新建一个标签,也可以指定一个commit id
  2. git tag -a <tagname> -m "blablabla..." 可以指定标签信息;
  3. git tag -s <tagname> -m "blablabla..." 可以用PGP签名标签;
  4. git tag 可以查看所有标签。
  5. git push origin <tagname> 可以推送一个本地标签;
  6. git push origin --tags 可以推送全部未推送过的本地标签;
  7. git tag -d <tagname> 可以删除一个本地标签;
  8. git push origin :refs/tags/<tagname> 可以删除一个远程标签。
原创粉丝点击