0%

Git常用命令

【介绍】MySQL多表和事物知识点总结

工作原理:



名词解释:


常用命令:

创建:


1. 创建一个新的本地仓库

git init

2. 克隆

git clone [url]

分支:


1. 创建分支

git branch develop

2. 查看本地分支 (字体颜色变绿,前面带有’*’号的是当前使用的分支)

git branch

3. 查看远程分支(远程分支会用红色表示出来)

git branch -r

4. 查看所有分支

git branch -a

5. 切换分支

git checkout

6. 切换到上一个分区

git checkout -

7. 新建一个分支并于指定的远程分支建立追踪关系

git branch   --track [local-branch]  [remote-branch]

8. 修改追踪关系
1. 切换分支 git checkout [local-branch] 2. 修改追踪仓库 git branch --set-upstream-to [remote-branch]

ps: 也可以在初次push的时候 加上-u参数

git push -u [remote-branch]

9. 删除分支

git branch -d [branch]

10. 删除远程分支

git push origin -delete [branch]

git branch -dr [remote-branch]

变化:


1. 比较两次修改的差异

git diff

2. 查看当前的工作目录和暂存区的状态

git status

添加、删除、提交:


1. 添加指定文件到暂存区

git add [file1] [file2]

2. 添加所有文件到暂存区

git add .

3. 添加指定目录以及子目录到暂存区

git add [dir]

4. 提交暂存区代码到仓库区

git commit -m [备注]

5. 提交指定文件到仓库区

git commmit [file1] [file2] ... -m [message]

6. 对上一次提交进行修改

git commit --amend  

7. 删除暂存区或者分支上的文件,同时工作区也不需要该文件

git rm [file]  (git rm=rm+git add)

8. 删除暂存区或分支上的文件,但本地继续使用,且不希望该文件被版本控制

git rm --cached [file]

同步:


1. 下载远程仓库的所有变动

git fetch [remote]

2. 显示所有的远程仓库

git remote -v

3. 将远程仓库的代码拉取下来与本地进行合并

git pull [remote-branch]

4. 上传本地指定分支到远程仓库

git push [remote-branch]

版本、撤销:


1. 显示当前分支版本的历史

git log

2. 显示指定文件的每一次变化

git log -p [file]

3. 显示指定文件在什么时间被怎样修改

git blame [file]

4. 恢复暂存区的指定文件到工作区

git checkout [file]

5. 恢复暂存区的所有文件到工作区

git checkout .

6. 重做工作区与暂存区,与上一次commit保持一致

git reset  —hard

参考文章:  http://www.ruanyifeng.com       英文PDF下载地址


-------------    本文结束  感谢您的阅读    -------------