139 lines
3.9 KiB
Markdown
139 lines
3.9 KiB
Markdown
## git 基本操作
|
||
|
||
|
||
#### 配置代理
|
||
http 协议代理
|
||
|
||
```bash
|
||
//设置全局代理
|
||
//http
|
||
git config --global http.proxy http://127.0.0.1:1080
|
||
//https
|
||
git config --global https.proxy http://127.0.0.1:1080
|
||
//使用socks5代理的 例如ss,ssr 1080是windows下ss的默认代理端口,mac下不同,或者有自定义的,根据自己的改
|
||
git config --global http.proxy socks5://127.0.0.1:1080
|
||
git config --global https.proxy socks5://127.0.0.1:1080
|
||
|
||
//只对github.com使用代理,其他仓库不走代理
|
||
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
|
||
git config --global https.https://github.com.proxy socks5://127.0.0.1:1080
|
||
//取消github代理
|
||
git config --global --unset http.https://github.com.proxy
|
||
git config --global --unset https.https://github.com.proxy
|
||
|
||
//取消全局代理
|
||
git config --global --unset http.proxy
|
||
git config --global --unset https.proxy
|
||
```
|
||
|
||
ssh 协议代理
|
||
|
||
```bash
|
||
//对于使用git@协议的,可以配置socks5代理
|
||
//在~/.ssh/config 文件后面添加几行,没有可以新建一个
|
||
//socks5
|
||
Host github.com
|
||
User git
|
||
ProxyCommand connect -S 127.0.0.1:1080 %h %p
|
||
|
||
//http || https
|
||
Host github.com
|
||
User git
|
||
ProxyCommand connect -H 127.0.0.1:1080 %h %p
|
||
```
|
||
|
||
#### 更新git
|
||
|
||
```bash
|
||
git update-git-for-windows
|
||
```
|
||
|
||
#### git常用命令
|
||
|
||
- 取消合并
|
||
|
||
当出现推送被拒,本地分支领先 远端分支,远端分支又有别人提交的代码时。
|
||
需要合并远程分支再提交,如果处理不了 需要先取消本地合并
|
||
|
||
```
|
||
git merge --abort
|
||
```
|
||
|
||
|
||
|
||
- git删除文件
|
||
|
||
|
||
|
||
1-1.仅删除远程仓库文件,不删除本地
|
||
|
||
```bash
|
||
git rm --cached */src/views/index.vue* # 注意文件路径,加上*号
|
||
git commit -m "delete remote file filename " # commit提交,无须add
|
||
git push origin master(此处是当前分支的名字) # 推送即可
|
||
```
|
||
|
||
|
||
|
||
1-2.仅删除远程仓库文件夹!!文件夹,不删除本地
|
||
|
||
```bash
|
||
git rm -r --cached */src/views* # 注意文件路径,加上*号 , 和删除文件区别在于 -r
|
||
git commit -m "delete remote file filename " # commit提交,无须add
|
||
git push origin master(此处是当前分支的名字) # 推送即可
|
||
```
|
||
|
||
|
||
|
||
2-1.删除远程仓库文件,同时删除本地文件 (区别在于 --cached)
|
||
|
||
```bash
|
||
git rm */src/views/index.vue* # 注意文件路径,加上*号
|
||
git commit -m "delete remote file filename " # commit提交,无须add
|
||
git push origin master(此处是当前分支的名字) # 推送即可
|
||
```
|
||
|
||
|
||
|
||
2-2.删除远程仓库文件夹!!文件夹,同时删除本地
|
||
|
||
```bash
|
||
git rm -r */src/views* #注意文件路径,加上*号 , 和删除文件区别在于 -r
|
||
git commit -m "delete remote file filename " # commit提交,无须add
|
||
git push origin master(此处是当前分支的名字) # 推送即可
|
||
```
|
||
|
||
|
||
|
||
- git revert 的用法
|
||
|
||
git revert 的作用是通过创建一个新的版本,这个版本的内容与我们要回退到的目标版本一样,但是HEAD指针是指向这个新生成的版本,而不是目标版本。
|
||
如果我们想恢复之前的某一版本(该版本不是merge类型),但是又想保留该目标版本后面的版本,记录下这整个版本变动流程,就可以用这种方法。
|
||
我们使用git revert HEAD命令就可以创建一个新的版本,此版本与上一个版本相同。
|
||
|
||
|
||
|
||
```
|
||
git revert HEAD :撤销前一次 commit
|
||
git revert HEAD^ :撤销前前一次 commit
|
||
git revert commit + (commit id): 撤销指定的版本,撤销也会作为一次提交进行保存。
|
||
|
||
```
|
||
|
||
|
||
|
||
|
||
|
||
```
|
||
git reset --soft HEAD^:将最近一次提交节点的提交记录回退到暂存区
|
||
git reset --mixed HEAD^:将最近一次提交节点的提交记录回退到工作区
|
||
git reset --hard HEAD^:将最近一次提交节点的提交记录全部清除
|
||
git revert是用一次新的commit来回滚之前的commit,git reset是直接删除指定的commit。
|
||
|
||
```
|
||
|
||
|
||
|
||
|
||
|