Git命令行

来源:互联网 发布:苏州团扇李晶淘宝店 编辑:程序博客网 时间:2024/05/16 17:06

1.创建目录

$ mkdir <repositoryName>

2.初始化新的repository

$ git init

3.添加文件

$ touche <newFile.text>

4.将远程仓库拷贝至本地

$ git clone http://...

5.切换到另一分支anotherBranchName

$ git checkout <anotherBranchName>

6.查看本地仓库状态

$ git status

7.添加所有修改

$ git add *

8.提交,并输入一行提交信息

$ git commit -m "" 

输入多行提交信息

$ git commit -m 'lots ofcommit message'

9.合并分支,此指令是将目标分支内容合并至当前分支

$ git merge <targetBranchName>

10.推到远程仓库

$ git push 

11.将远程仓库更新至本地

$ git pull

12.查看git日志

$ git log 
//打印日志—图形化展现分支合并历史记录$ git log --oneline --graph --decorate 

13.修改git上远程仓库的地址

//删除原有的远程仓库地址$ git remote rm origin//连接gitHub$ git remote add origin <url>

14.基于某分支创建新的分支

$ git branch <new-branch_name> <old_branch_name>

15.基于某次提交创建新的分支

$ git branch <new_branch_name> <commit code>

此处需要找到对应的commit的code,可以通过git log打印commit列表获得,或者直接从commit列表页获得,或者是进入到远程仓库找到那次commit,copy commit code

16.回滚修改

这种回滚是有痕迹的,它真是的意思是在生成一次提交,将之前的某次提交反向修改回来。
git log 某次提交日志,找到想要回滚某次commit,用以下指令回滚:

$ git revert <commit code> 
0 0