删除未命名的 git 分支
Removing unnamed git branch
不知何故,我最终得到了这样的项目结构:
> git log --graph --oneline --all
* a72aed6 (master) feat(data:model:user): modified db service
* 099becd feat(data:model:user): added CRUD for user model
* 59ac87d refactor(): separating concerns
* dfb983f chore(data:api): removed graphql testing cruft
* aa92817 feat(data:db): setup pg pool connection and query in db/index.ts
* ee03d48 feat(wf): added express
* 184cef0 feat(data:db): added pg
| * 32aedba chore(data:api): removed graphql testing cruft
| * a6825d2 feat(data:db): setup pg pool connection and query in db/index.ts
| * 4a901b1 feat(wf): added express
| * e5753c5 feat(data:db): added pg
|/
* 94426bc (HEAD) feat(qc:test:jest): added test coverage script
* 6126689 feat(build:deploy): added webpack typescript integrations
* 172da85 feat(build:deploy): added webpack-cli
* bab6afa feat(qc): added husky
* c570f33 feat(vcs): added git
我已经尝试了所有方法(reset --hard
、cherry-pick
、rebase -i, drop
等)来删除提交 e5753c5
到 32aedba
,它们被错误地显示为在我赶时间完成项目的一部分之后,重复了 4 次提交:)
我可以执行什么命令来实现以下输出:
> git log --graph --oneline --all
* a72aed6 (master) feat(data:model:user): modified db service
* 099becd feat(data:model:user): added CRUD for user model
* 59ac87d refactor(): separating concerns
* dfb983f chore(data:api): removed graphql testing cruft
* aa92817 feat(data:db): setup pg pool connection and query in db/index.ts
* ee03d48 feat(wf): added express
* 184cef0 feat(data:db): added pg
* 94426bc feat(qc:test:jest): added test coverage script
* 6126689 feat(build:deploy): added webpack typescript integrations
* 172da85 feat(build:deploy): added webpack-cli
* bab6afa feat(qc): added husky
* c570f33 feat(vcs): added git
我尝试过的前后示例:
git checkout 32aedba
git rebase -i 94426bc
# `drop` to the above commits
git log --graph --oneline --all
# Returns as above, with HEAD at 94426bc
git checkout 32aedba
git reset --hard HEAD~4
# `drop` to the above commits
git log --graph --oneline --all
# Returns as above, with HEAD at 94426bc
首先,陈旧的分支没有害处,所以我不清楚你的目标。只是介绍吗?如果是,您只能输出 master
和
git log --graph --oneline master
但让我们接受前提:如何摆脱不需要的提交?
您必须找到提交 32aedba
中的哪些引用,其中的内容类似于
git branch --contains 32aedba
然后用
删除这些分支
git branch -D <branch>
(-D
而不是 -d
因为它将被取消合并并且需要强制)
另一种方法(参见 Lasse 的评论)是在您的命令中使用
输出引用
git log --graph --oneline --all --decorate
git push origin --delete [branchName]
删除远程分支
不知何故,我最终得到了这样的项目结构:
> git log --graph --oneline --all
* a72aed6 (master) feat(data:model:user): modified db service
* 099becd feat(data:model:user): added CRUD for user model
* 59ac87d refactor(): separating concerns
* dfb983f chore(data:api): removed graphql testing cruft
* aa92817 feat(data:db): setup pg pool connection and query in db/index.ts
* ee03d48 feat(wf): added express
* 184cef0 feat(data:db): added pg
| * 32aedba chore(data:api): removed graphql testing cruft
| * a6825d2 feat(data:db): setup pg pool connection and query in db/index.ts
| * 4a901b1 feat(wf): added express
| * e5753c5 feat(data:db): added pg
|/
* 94426bc (HEAD) feat(qc:test:jest): added test coverage script
* 6126689 feat(build:deploy): added webpack typescript integrations
* 172da85 feat(build:deploy): added webpack-cli
* bab6afa feat(qc): added husky
* c570f33 feat(vcs): added git
我已经尝试了所有方法(reset --hard
、cherry-pick
、rebase -i, drop
等)来删除提交 e5753c5
到 32aedba
,它们被错误地显示为在我赶时间完成项目的一部分之后,重复了 4 次提交:)
我可以执行什么命令来实现以下输出:
> git log --graph --oneline --all
* a72aed6 (master) feat(data:model:user): modified db service
* 099becd feat(data:model:user): added CRUD for user model
* 59ac87d refactor(): separating concerns
* dfb983f chore(data:api): removed graphql testing cruft
* aa92817 feat(data:db): setup pg pool connection and query in db/index.ts
* ee03d48 feat(wf): added express
* 184cef0 feat(data:db): added pg
* 94426bc feat(qc:test:jest): added test coverage script
* 6126689 feat(build:deploy): added webpack typescript integrations
* 172da85 feat(build:deploy): added webpack-cli
* bab6afa feat(qc): added husky
* c570f33 feat(vcs): added git
我尝试过的前后示例:
git checkout 32aedba
git rebase -i 94426bc
# `drop` to the above commits
git log --graph --oneline --all
# Returns as above, with HEAD at 94426bc
git checkout 32aedba
git reset --hard HEAD~4
# `drop` to the above commits
git log --graph --oneline --all
# Returns as above, with HEAD at 94426bc
首先,陈旧的分支没有害处,所以我不清楚你的目标。只是介绍吗?如果是,您只能输出 master
和
git log --graph --oneline master
但让我们接受前提:如何摆脱不需要的提交?
您必须找到提交 32aedba
中的哪些引用,其中的内容类似于
git branch --contains 32aedba
然后用
删除这些分支git branch -D <branch>
(-D
而不是 -d
因为它将被取消合并并且需要强制)
另一种方法(参见 Lasse 的评论)是在您的命令中使用
输出引用git log --graph --oneline --all --decorate
git push origin --delete [branchName] 删除远程分支