Git 常用命令(转)
一、语法
1、Git查看远程仓库名称
git remote -v
1
2、git 更换 url
git remote set-url origin <new url>
1
3、添加远程关联
git remote add origin <url>
1
4、删除远程关联
git remote remove <url>
1
5、分支操作
#查看本地分支
git branch
#查看所有分支
git branch -a
#创建分支
git branch <name>
#切换分支
git checkout <name>
#创建+切换分支
git checkout -b <name>
#合并某分支到当前分支
git merge <name>
#删除分支
git branch -d <name>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
6、添加至暂存区
git add .
1
7、拉回远程版本库的提交
git pull
git pull origin master
1
2
8、将本地项目给提交到服务器中
git push
git push origin master
1
2
9、提交当前repos的所有的改变
git commit -a <备注>
git commit -m <备注> 提交暂存区的文件
git commit -am <备注> 提交跟踪过的文件
1
2
3
10、 查看最近或某一次提交修改的文件列表相关命令
git log --name-status #每次修改的文件列表, 显示状态
git log --name-only #每次修改的文件列表
git log --stat #每次修改的文件列表, 及文件修改的统计
git whatchanged #每次修改的文件列表
git whatchanged --stat #每次修改的文件列表, 及文件修改的统计
git show #显示最后一次的文件改变的具体内容
git show -5 #显示最后 5 次的文件改变的具体内容
git show commitid #显示某个 commitid 改变的具体内容
1
2
3
4
5
6
7
8
11、回退merge操作
#查看merge操作的上一个提交记录的版本号
git reflog
#回滚到merge之前的状态
git reset --hard <版本号>
1
2
3
4
12、远程分支覆盖本地分支
丢弃本地变更 重置为远端分支内容
git reset --hard origin/branchName
1
13、切换 git的 origin数据源
git remote -v //查看远程origin
git remote rm origin // 删除远程origin
git remote add origin 地址 //添加源,origin为别名,可以自己取
1
2
3
4
5
二、例子
1、 远程仓库相关命令
(1) 检出仓库
git clone git://github.com/jquery/jquery.git
1
(2) 查看远程仓库
git remote -v
1
(3) 添加远程仓库
git remote add [name] [url]
1
(4) 删除远程仓库
git remote rm [name]
1
(5) 修改远程仓库
git remote set-url --push [name] [newUrl]
1
(6) 拉取远程仓库
git pull [remoteName] [localBranchName]
1
(7) 推送远程仓库
git push [remoteName] [localBranchName]
1
*如果想把本地的某个分支test提交到远程仓库,并作为远程仓库的master分支,或者作为另外一个名叫test的分支,如下:
git push origin test:master // 提交本地test分支作为远程的master分支
git push origin test:test // 提交本地test分支作为远程的test分支
1
2
(8) 创建分支
git branch [分支名]
————————————————
版权声明:本文为CSDN博主「JYeontu」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Twinkle_sone/article/details/118482718
1、Git查看远程仓库名称
git remote -v
1
2、git 更换 url
git remote set-url origin <new url>
1
3、添加远程关联
git remote add origin <url>
1
4、删除远程关联
git remote remove <url>
1
5、分支操作
#查看本地分支
git branch
#查看所有分支
git branch -a
#创建分支
git branch <name>
#切换分支
git checkout <name>
#创建+切换分支
git checkout -b <name>
#合并某分支到当前分支
git merge <name>
#删除分支
git branch -d <name>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
6、添加至暂存区
git add .
1
7、拉回远程版本库的提交
git pull
git pull origin master
1
2
8、将本地项目给提交到服务器中
git push
git push origin master
1
2
9、提交当前repos的所有的改变
git commit -a <备注>
git commit -m <备注> 提交暂存区的文件
git commit -am <备注> 提交跟踪过的文件
1
2
3
10、 查看最近或某一次提交修改的文件列表相关命令
git log --name-status #每次修改的文件列表, 显示状态
git log --name-only #每次修改的文件列表
git log --stat #每次修改的文件列表, 及文件修改的统计
git whatchanged #每次修改的文件列表
git whatchanged --stat #每次修改的文件列表, 及文件修改的统计
git show #显示最后一次的文件改变的具体内容
git show -5 #显示最后 5 次的文件改变的具体内容
git show commitid #显示某个 commitid 改变的具体内容
1
2
3
4
5
6
7
8
11、回退merge操作
#查看merge操作的上一个提交记录的版本号
git reflog
#回滚到merge之前的状态
git reset --hard <版本号>
1
2
3
4
12、远程分支覆盖本地分支
丢弃本地变更 重置为远端分支内容
git reset --hard origin/branchName
1
13、切换 git的 origin数据源
git remote -v //查看远程origin
git remote rm origin // 删除远程origin
git remote add origin 地址 //添加源,origin为别名,可以自己取
1
2
3
4
5
二、例子
1、 远程仓库相关命令
(1) 检出仓库
git clone git://github.com/jquery/jquery.git
1
(2) 查看远程仓库
git remote -v
1
(3) 添加远程仓库
git remote add [name] [url]
1
(4) 删除远程仓库
git remote rm [name]
1
(5) 修改远程仓库
git remote set-url --push [name] [newUrl]
1
(6) 拉取远程仓库
git pull [remoteName] [localBranchName]
1
(7) 推送远程仓库
git push [remoteName] [localBranchName]
1
*如果想把本地的某个分支test提交到远程仓库,并作为远程仓库的master分支,或者作为另外一个名叫test的分支,如下:
git push origin test:master // 提交本地test分支作为远程的master分支
git push origin test:test // 提交本地test分支作为远程的test分支
1
2
(8) 创建分支
git branch [分支名]
————————————————
版权声明:本文为CSDN博主「JYeontu」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Twinkle_sone/article/details/118482718
浙公网安备 33010602011771号