0

Somehow, I've ended up with a project structure as such:

> 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

I have tried everything (reset --hard, cherry-pick, rebase -i, drop, etc) to remove commits e5753c5 to 32aedba, which have mistakenly appeared as duplicates of the 4 commits after while I was rushing part of the project for a deadline :)

What command can I perform to achieve the following output:

> 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

Example before and after of what I've tried:

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
Nick Bull
  • 9,518
  • 6
  • 36
  • 58
  • Try adding --decorate to your log command, see if it then lists the branch that keeps these commits alive. – Lasse V. Karlsen Feb 24 '20 at 12:32
  • @LasseV.Karlsen Thank you for your suggestion - I had tried that, and it didn't achieve anything in this case. I believe it was because of a tag rather than a branch – Nick Bull Feb 24 '20 at 12:39
  • @NickBull: `--decorate` should show commits reachable via tag as, e.g., `* a123456 (tag: v1.2) commit subject line here` – torek Feb 24 '20 at 19:00
  • @torek You are right! I omitted the tag from the above output like a fool :p – Nick Bull Feb 25 '20 at 09:00

2 Answers2

1

First of all, a stale branch is doing no harm, so your goal is unclear to me. Is it only presentation? If yes, you could output only master with

git log --graph --oneline master

But let's accept the premise : how to get rid of the unwanted commits?

You'd have to find which references are on commit 32aedba with something along the lines of

git branch --contains 32aedba

then delete these branches with

git branch -D <branch>

(-D rather than -d because it will be unmerged and will require force)

An alternative (see Lasse's comment) would be to output refs in your command with

git log --graph --oneline --all --decorate
Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
  • I'm unsure, mostly because I'm inexperienced in my Git workflow messing up, but I believe it was very similar to the above - when I deleted a tag on the branch, the branch disappeared. Assuming that this is a similar cause to what you've posted. And you are right that a stale branch doesn't do any harm, but many stale branches could be confusing! – Nick Bull Feb 24 '20 at 12:38
  • @NickBull: in Git, tags aren't on *branches*, they're on *commits*. In fact almost everything is on commits—branch names and tag names are just for puny humans. :-) In any case once you delete *all* names by which you can find some commit(s), you stop finding those commit(s). The key concept here is *reachability*. See http://think-like-a-git.net/ – torek Feb 24 '20 at 18:58
  • @torek Awesome resource! Thank you :) – Nick Bull Feb 25 '20 at 09:03
-1

git push origin --delete [branchName] Delete a remote branch

ParagDineshGupta
  • 210
  • 2
  • 10