git 常用的命令

git常用的命令

$ git help <command> # 显示command的help

$ git show # 显示某次提交的内容 git show $id

$ git status

初始化操作

$ git config --global user.name <name> #设置提交者名字

$ git config --global user.email <email> #设置提交者邮箱

$ git config --global core.editor <editor> #设置默认文本编辑器

$ git config --global merge.tool <tool> #设置解决合并冲突时差异分析工具

$ git config -list #检查已有的配置信息

$ git init #初始化本地版本库

$ git init project1 #等价于 $ mkdir project1 && cd project1 && git init

查看、添加、提交、删除、找回,重置修改文件

$ git add <file> # 将工作文件修改提交到本地暂存区

$ git add . # 将所有修改过的工作文件提交暂存区

$ git rm <file> # 从版本库中删除文件

$ git mv <old> <new> #文件重命名

$ git commit -m <file> #提交指定文件

$ git commit -m “commit message” #提交所有更新过的文件

$ git commit -amend #修改最后一次提交

$ git commit -a  #相当于运行 git add 把所有当前目录下的文件加入暂存区域再运行git commit.

1) 远程仓库相关命令

复制远程仓库到本地: git clone git://github.com/jquery/jquery.git

查看远程仓库: git remote -v

添加远程仓库: git remote add [name] [url]

删除远程仓库: git remote rm [name]

修改远程仓库: git remote set-url --push [name] [newUrl]

拉取远程仓库: git pull [remoteName] [localBranchName]

推送远程仓库: git push [remoteName] [localBranchName]

提交本地test分支作为远程的master分支: git push origin test:master

提交本地test分支作为远程的test分支: git push origin test:test

2) 分支的相关操作

$ git branch #显示所有本地分支

$ git checkout <branch/tagname> #切换到指定分支或标签

$ git branch <new-branch> #创建新分支

$ git branch -d <branch> #删除本地分支

$ git tag #列出所有本地标签

$ git tag <tagname> #基于最新提交创建标签

$ git tag -d <tagname> #删除标签

3)合并与衍合

$ git merge <branch> #合并指定分支到当前分支

$ git rebase <branch> #衍合指定分支到当前分支

原文地址:https://www.cnblogs.com/lishuai0214/p/4263968.html