用于在远程仓库的操作
git remote -v
- 查看当前 git 仓库的远程
- 查看当前 git 仓库的远程
git remote show [remote]
- 显示某个远程仓库的信息
- 显示某个远程仓库的信息
git remote add [shortname] [url]
- 添加远程版本库,
shortname
为本地版本库
- 添加远程版本库,
git remote rm [name]
- 删除远程仓库
git remote rename [old_name] [new_name]
- 修改仓库名
详情看:连接远程仓库remote
版本回退(+撤回上一次提交)
git reset --soft HEAD^
- 撤回上一次的 commit
操作
- 等同于 git reset --soft HEAD~1
- 如果进行了两次 commit
提交,都想撤回,可以使用 git reset --soft HEAD~2
- 扩展
--mixed
- 不删除工作空间改动代码,撤销
commit
,并且撤销git add .
操作,这个为默认参数,git reset --mixed HEAD^
=git reset HEAD^
- 不删除工作空间改动代码,撤销
--soft
- 不删除工作空间改动代码,撤销
commit
,不撤销git add .
- 不删除工作空间改动代码,撤销
--hard
- 删除工作空间改动代码,撤销
commit
并撤销git add .
- **注意:此操作后就恢复到了上一次的 ****
commit
**状态。
- 删除工作空间改动代码,撤销
git commit --amend
- 如果只是
commit
注释写错了,只想改一下注释,只需要使用该命令,此时会进入默认vim
编辑器,修改注释完成后保存就好了。 - 关联:
- 如果只是
以 ;
分割多个 git
命令
- 如题
别名
-
命名别名能提高可重用性
git config --global alias.[alias name] '[command]'
使用 git config --global alias.show-origin 'remote -v' ' 将 show-origin 作为 remote -v 的别名
设置代理 proxy
- 在有条件的情况下, 设置代理能为我们节省很多时间, 让我们开始
详情看:设置代理 proxy# http/https 协议, port 需与代理软件设置一致 git config --global http.proxy http://127.0.0.1:port # socks5 协议 git config --global http.proxy socks5://127.0.0.1:port
设置全局 .gitignore
- 在根目录下的
.gitignore_global
文件中(没有则新增)添加忽略.DS_Store
文件规则-
echo .DS_Store >> ~/.gitignore_global
-
将这个全局的
.gitignore
文件加入Git
的config
中git config --global core.excludesfile ~/.gitignore_global
-
分支
详细:分支操作
本地分支
- 查看所有分支(本地和远程)
-
git branch -a
-
- 查看本地分支,并且当前分支会用
*
标记-
git branch
-
- 创建新分支
-
git branch 新分支名称
-
- 切换分支
-
git checkout 分支名称
-
- 创建分支的同时, 切换到该分支上
git checkout -b 新分支名称
- 删除本地分支
-
git branch -d 分支名称
- 如果删除时报错:
error: The branch '分支名称' is not fully merged.(分支未完全合并)
,可以使用强制删除git branch -D 分支名称
- 如果删除时报错:
-
远程
- 查看远程分支列表
-
git branch -r
-
- 删除远程分支
git push origin :分支名称
- ⚠️注意:分支名称前面有个冒号, 分支名称前的冒号代表删除
- ⚠️注意:分支名称前面有个冒号, 分支名称前的冒号代表删除
评论区