git相关工具的安装和使用,如 Git Bash
,GitDesktop
等。
二、git 工具
01 Git Desktop
download code: https://github.com/desktop/desktop/tags
download package: https://github.com/shiftkey/desktop/releases
02 Git Bash
Git Bash 是一个在 Windows 系统上模拟 Linux 环境的命令行界面,是一个完整的命令行环境,可以像普通的Unix或Linux终端一样执行各种命令。
1. Git Bash修改默认打开之后的路径
https://blog.csdn.net/zzfenglin/article/details/54646541
03 git flow
git flow
is a branch manage tool to help team manage and release program better. Use command below to install it on ubuntu.
sudo apt-get install git-flow
master
: 永远保持稳定和可发布的状态develop
: 用于集成所有的开发分支; 代表了最新的开发进度; 功能分支、发布分支和修复分支都从这里分支出去,最终合并回这里feature
: 用于开发新功能; 从 develop 分支创建,开发完成后合并回 develop 分支; 命名规范feature/feature-name
release
: 用于准备新版本的发布; 从 develop 分支创建,进行最后的测试和修复,然后合并回 develop 和 master 分支,并打上版本标签; 命名规范release/release-name
hotfix
: 用于修复紧急问题; 从 master 分支创建,修复完成后合并回 master 和 develop 分支,并打上版本标签; 命名规范hotfix/hotfix-name
work flow
git flow init
# 开发新功能
# develop is default base branch
git flow feature start new-feature
git flow feature finish new-feature
# explicitly specify the base branch
git flow feature start new-feature-name base-branch
# 测试和修复
git flow release start v1.0.0
git flow release finish v1.0.0
# 修复紧急问题
git flow hotfix start hotfix-1.0.1.
git flow hotfix finish hotfix-1.0.1
04 git emoji
Emoji | Code | Usage |
---|---|---|
🎉 | :tada: |
Initial commit or celebration. |
✨ | :sparkles: |
Introducing a new feature. |
🐛 | :bug: |
Fixing a bug. |
🔥 | :fire: |
Removing code or files. |
📝 | :memo: |
Writing docs or updating comments. |
🚑 | :ambulance: |
Quick fix (hotfix). |
♻️ | :recycle: |
Refactoring code. |
🔨 | :hammer: |
Developing or modifying tools. |
🚀 | :rocket: |
Performance improvements. |
✅ | :white_check_mark: |
Adding tests. |
📦 | :package: |
Adding or updating dependencies. |
💄 | :lipstick: |
Improving UI or cosmetic changes. |
🐎 | :racehorse: |
Improving performance. |
🔧 | :wrench: |
Modifying configurations. |
🌟 | :star: |
Improving existing functionality. |
⚙️ | :gear: |
Configuration-related changes. |
🚚 | :truck: |
Moving or renaming files. |
🔒 | :lock: |
Fixing security issues. |
🗑️ | :wastebasket: |
Removing deprecated code. |
05 git-filter-repo
install
# 下载git-filter-repo工具
git clone https://github.com/newren/git-filter-repo.git
# 安装
cd git-filter-repo/
sudo cp git-filter-repo /usr/local/bin
Another method to install it
pip3 install git-filter-repo
delete file and folder from git
NOTE: If you use `git-filter-repo` to delete files, all history commits ID will be changed, even the commits that inherit from parent branch.删除指定文件的git记录
# 下载对应的库(如果不重新下载,可能会出错,参照后面的说明)
git clone url
# 删除记录。以下示例为删除了一个PDF文件。这个操作会删除远程仓库链接和分支的配置信息。
git filter-repo --invert-paths --path "2019 Fast 3D Line Segment Detection From Unorganized Point Cloud.pdf"
# 删除记录。以下示例为删除了一个文件夹。这个操作会删除远程仓库链接和分支的配置信息。
git filter-repo --invert-paths --path docs
# 强制上传到远程仓库,url为远程仓库的链接,branch为指定的分支。必须添加"--force"选项,否则会失败
git push --force url branch
如果没有重新下载,直接删除记录可能会遇到如下错误
Aborting: Refusing to destructively overwrite repo history since
this does not look like a fresh clone.
这是 git filter-repo
要求您在一个新克隆的仓库上运行以确保安全。这个安全措施是为了防止无意中重写并破坏正在使用的仓库的历史。由于 git filter-repo
可能会永久修改仓库的提交历史,使用一个新克隆的仓库可以避免错误地覆盖重要的工作。
如果遇到以下错误
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using
说明没有指定远程仓库的地址和分支。
删除所有历史记录中当前提交不存在的文件
# 删除所有历史记录中当前提交不存在的文件
git filter-repo --invert-paths --path-glob '!*'
# 压缩并清理仓库
git reflog expire --expire=now --all
git gc --prune=now --aggressive
# 推送到远程仓库
git push --force