收集一些有趣&好用的git命令
git commit -m "commit title" -m "commit description"
git commit accepts several message flags (-m) to allow multiline commits
谢谢。 如果您可以还原 /docs Git 子树中的更改,我将合并。 历史内容的文档编辑需要在 hugoDocs 存储库中完成。
git log fileName
(如果文件修改记录太多,则使用 git log -number fileName)
找到想要还原的版本的commit_id
git checkout ${commit} fileName
即
git checkout 8f7891e70c51163185fbbd878b4925d11b6a2a93 docs/content/en/news/0.82.0-relnotes/index.md
git rm -rf .idea
git config --global url."https://".insteadOf git://
之后.gitconfig中会多出一行参数设置:
[url "https://"] insteadOf = git://
设置之后,使用git://
,或者https://
两种方式都会默认变成https://
的形式
git config --global http.proxy 'socks5://127.0.0.1:1080' && git config --global https.proxy 'socks5://127.0.0.1:1080'
如 2.0到2.1
#!/bin/bash set -e # Add tag, auto incr tag latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`) echo "tag为:" echo $latest_tag new_tag=$(echo $latest_tag | awk -F. -v OFS=. '{++$NF;print};') echo "新的tag为:" echo $new_tag git tag -a "$new_tag" -m "$commit_msg"
关于 awk -v OFS
git tag 和git tag -a的细微区别:
-a必须要有tag说明,而不带-a即直接git tag
不会强制要求写说明。当使用git tag -m时,效果和git tag -a -m是一样的
git remote rm origin
git remote add origin 新的远程仓库地址
git rebase -i HEAD~2
(如果想合并之前N个commit,则将2改为N)
-i 即 interactive
git rebase --interactive HEAD~[N]即交互式 rebase。
简写为git rebase -i HEAD~[N]
N 为想要合并的提交的数量,从最近的一次提交往前数 (N >= 2)
通过将多个临时的小的提交合并成一次提交,然后将整理好的代码 push 给远端
(历史记录是按照时间排序的,时间近的排在前面)
将第二行的pick改为squash(即压缩此提交)
然后wq保存
再 git log查看:
git push -f
同上
git rebase -i 想合并在一起的最后一次提交的再前一次提交
(或 git rebase -i HEAD~n, n为要合并的提交次数)
将第一行之后的pick
改为s
或squash
(挤压,压进 之意)
wq保存退出,git会压缩提交历史
若有冲突,需进行修改
修改完成后,需要保存
git add .
git rebase --continue
若想退出放弃此次压缩,执行命令: git rebase --abort
若没有冲突(或 冲突已解决), 则会出现一个 commit message 编辑页面,修改 commit message,然后 输入:wq
之后 git push -f 或 git push --force,推送到远程
Git 合并多个 commit,保持历史简洁
Copyright © 2023 leiyu.cn. All Rights Reserved. 磊宇云计算 版权所有 许可证编号:B1-20233142/B2-20230630 山东磊宇云计算有限公司 鲁ICP备2020045424号
磊宇云计算致力于以最 “绿色节能” 的方式,让每一位上云的客户成为全球绿色节能和降低碳排放的贡献者