For the following Git log, how do I prune off (remove completely) the branch which attaches at 15acb99 and ends in the stash. It is no longer needed.
$ git log --oneline --graph --decorate --all
* bc03ce7 (HEAD -> main) Implemented basic Auth0 functionality
* 38ed987 updated Readme
* 441f915 Addded graphql-codegen and embelished query org_unit
* c724f4a added Apollo Rover
* 6efbd90 Merge branch 'codegen'
|\
| * fc891c1 correct .gitignore to ignore node_modules
* | 128a914 removed pnpm
|/
| * f187ecb (refs/stash) WIP on auth0: 7fb18d9 Login/Out button implmented on Home page
| |\
| | * de4b497 index on auth0: 7fb18d9 Login/Out button implmented on Home page
| |/
| * 7fb18d9 Login/Out button implmented on Home page
| * 32e5959 Auth0 added and working - log in and display profile, basic protection of routes
|/
* 15acb99 added apollo packages and first query, add /clubs route to display OrgUnits
* 56c88ea Added Vue Router to Frontend
* 8e5bb96 Frontend initiated
* 769e86d Initial seed data added
* 592c8ac create tables OrgUnit and Person
* 3563cf3 init hasura migrations and metadata
* 93a20c7 init
I am terrified of screwing this up.
CodePudding user response:
As you rightly say, it's just a stash. Simply say
git stash clear
and the unwanted commits (and no others) will all be gone from the graph.
Why? Well, the basic rule of Git commit persistence is that only reachable commits persist. "Reachable" means that a commit is pointed by a ref name (branch, tag, stash) or is the parent, at some remove, of such a commit. By definition, if you delete the stash pointer that is keeping f187ecb alive, everything from there thru 32e5959 will become unreachable and will vanish from the log output — which is exactly what you wanted. Note that we didn't actually delete any commits — just a name. But those commits will eventually be deleted as well.
Observe also that you could have gotten the same outward effect by saying git log --oneline --graph --decorate --branches. That would have removed the stash from the git log output without changing your repo in any way (i.e. without actually clearing the stash).
CodePudding user response:
In this case your best bet is an interactive rebase. But having merge commits makes that process a bit harder than usual.
git rebase -i 15acb99
Where the commit at the end of the command indicates where to start rewriting your history.
This will pop up an editor with the list of commits between 15acb99 and the last commit in your history.
You can mark the commits you want to keep with k and then squash the commits you want to keep the content of with s but combine the changes with the next commit in line.
From what I can tell you want to squash 6efbd90.
