git
git 推送时显示推送进度
git push --progress
# or(显示更多的信息)
git push --verboseSSL certificate problem: unable to get local issuer certificate
git config --global http.sslVerify false获取最近一次提交的 commit hash
import execa from 'execa'
// 获取最近一次提交的 commit hash
const commit = execa.sync('git', ['rev-parse', 'HEAD']).stdout.slice(0, 7)Git Worktree
将当前本地仓库复制一份到别的路径。
# -b branch 可选,如果不传,那么分支名为复制仓库的目录名
# git worktree add <path> [-b branch]
git worktree add ../activity-h5-changan -b react-native如何查看当前仓库 git 配置和全局 git 配置
当前
git config --local -l全局
git config --global -l遇到不能 push 代码的问题
warning: redirecting to https://gitlab.bestpay.com.cn/wx/utilitiesapp.git/
error: unable to rewind rpc post data - try increasing http.postBuffer
error: RPC failed; curl 65 HTTP/2 stream 7 was reset
fatal: the remote end hung up unexpectedly
Everything up-to-date根据报错提示,增加 http.postBuffer。
git config --global http.postBuffer 1048576000解决上传 git 代码时卡住问题
全局设置
git config --global sendpack.sideband false设置当前仓库
git config --local sendpack.sideband false通过以下命令查看仓库 git 配置:
git config --local -l克隆时指定仓库
git clone -b dev https://asdfa.xasdf本地分支推送到与当前分支不同名的远程分支
git push origin <本地分支名>:<远程分支名(不带远程仓库名)>git SSL certificate problem: unable to get local issuer certificate
安装完 git 后,第一次 git clone 时遇到这个问题。
这个问题是由于没有配置信任的服务器 HTTPS 验证。默认,cURL 被设为不信任任何 CAs,就是说,它不信任任何服务器验证。
只需要执行下面命令就可以解决:
git config --global http.sslVerify falsegitee 怎么查看自己的用户名
直接在 url 路径上看。比如下面这个 url,Lukecheng 就是自己的用户名。
https://gitee.com/Lukechenggg允许没有任何文件改动的提交
git commit --allow-empty -m 'wori'第一次推代码
第一次推送代码的时候,必须设置邮箱和昵称。
git config --global user.email "lukecheng233@163.com"
git config --global user.name "lukecheng"修改最后一次提交的 commit 信息
git commit --amend -m '修改的信息'跳过暂存,直接提交
git commit -a -m 'abc'将多个提交合并为一个
执行命令后,在控制台会出现一些交互选项。注意!从上往下,第一个是时间上最早的提交!依次往下,提交时间距离现在越来越近。
# 第一种方式
# 将最近的 5 次提交合并为一个提交
git rebase -i HEAD~5
# 第二种方式
# 参数的第一个 commit-id 的意思是:假设你想要把最近的 5 次提交合并为一个提交,
# 那这个 commit-id 就是 5 次提交中在时间顺序上最先的提交的上一次提交。
git rebase -i <commit-id> [commit-id] # 左闭右开
# 下面这行命令的意思是:将当前分支移植到指定分支或指定 commit 之上。
git rebase -i <commit>进入交互式命令行后,(从上往下)第一个提交使用 pick 或 reword(如果你想要修改提交 commit 信息)。
其它提交使用 squash 或 fixup。
pick:使用commit。
reword:使用commit,修改commit信息。
squash:使用commit,将commit信息合入上一个commit。
fixup:使用commit,丢弃commit信息。最后修改完后,按 :wq 退出。
变基
# 将当前处于的分支变基到目标分支(master)
git rebase master可能需要解决冲突:
# 查看冲突的文件
git status
# 暂存已解决冲突的文件
git add .
# 继续变基
git rebase --continue# 放弃变基
git rebase --abortgit rebase 和 git merge 的区别(变基和合并的区别)
如果你想要将 b 分支改动合并到 a 分支上,那么变基应该切换到 b 分支,合并应该切换到 a 分支上。
解决从 github 上下载仓库很慢的问题
方法一 可以利用 gitee 提供的功能将 github 的仓库导入到 gitee 中,再然后使用 gitee 下载,速度飞快。
方法二 或者,git clone 时带上参数 --depth 1。它的意思是会让 clone 下来的仓库是最近的一个 commit 的文件夹状态,而不是整个文件夹的记录。
git clone https://github.com/xxx --depth 1
# 再然后将整个文件夹的状态下载下来
git fetch --unshallow方法三 使用镜像地址下载,但可能镜像还没有复制过来仓库。
在 vscode 中使用 git 管理工具
首先,你可能需要下载这些插件:
- mhutchie.git-graph
- donjayamanne.githistory
- eamodio.gitlens
接着打开 vscode 侧边栏左侧的这个图标:

source control
可以控制代码的修改、提交、推送等。

repositories
可以比较当前工作区文件与某个分支,标签,hash 引用的不同。

file history
可以查看当前选中文件的历史修改记录。

其它
还有其它更多的一些功能,可以自己去看一看,试一试。
git 的基础命令行操作
撤销提交
可以理解为,反着做一个 commitId 做的事情。
撤销某个提交
# -n 代表撤销后,需要重新提交一个信息
git revert -n commitId撤销多个提交
git revert -n commit-idA..commit-idB将某个文件内容作为提交信息
git commit -F ./xxx.md本地分支推送到远端某个公共分支
git push orgin xxx添加远程仓库
git remote add <远程仓库名> <远程仓库url>比如
git remore add suibian https:xxx.xxx.com显示所有远程仓库
git remote显示所有远程仓库详细信息
git remote -vTIP
为什么 git remote -v 后可能会出现 fetch、push 的原因,可以看看这篇文章:https://blog.csdn.net/u014143369/article/details/123754292
修改远程仓库 push 地址
git remote set-url --push <远程仓库别名> <远程仓库URL>推送到所有远端
添加一个名为 all 的远端,这个步骤没有 git 命令的支持,需要打开 .git/config 文件,在最底部添加如下:
[remote "all"]
url = https://gitee.com/xxx
url = https://github.com/xxx更新所有分支,但不会合并代码
git fetch获取远端更新
git fetch <远程仓库名>查看本地和远程所有分支
git branch -a只查看本地分支
git branch只查看远程分支
git branch -r修改本地分支名
git branch -m oldName newName创建本地分支并且与远程分支同步
git checkout -b test origin/test把某个远程分支获取到本地
git fetch origin devlepmentgit pull
git pull 操作其实是 git fetch 和 git merge 的合并操作。
ssh 公钥
https://git-scm.com/book/zh/v2/服务器上的-Git-生成-SSH-公钥
git 删除远程仓库
git remote rm xxx