Reputation: 181
I am trying to get a command in git which can help me fetch list of all the branches or my code and also list down all the hashcode in front of same . As I want to delete all my stale branches and keep it safe for later retrieval.
To List all the branches following command is enough.
Git branch -r
to get the hashcode for a branch
git rev-parse <BranchName>
can I get one command where it list all branches and hashcode in front of it.
Upvotes: 2
Views: 221
Reputation: 2704
I used cut
and while
loops to reach to the solution:
git branch -r -l | cut -d " " -f 3 | while read i; do echo "$i: $(git rev-parse $i)"; done
Upvotes: 1
Reputation: 30878
git for-each-ref refs/remotes --format="%(objectname) %(refname:lstrip=2)"
git for-each-ref
outputs information on all local refs.
refs/remotes
is the pattern for remote tracking branches. Only the refs matching the pattern will be printed.
--format
formats the output. Here %(objectname)
refers to the commit hash. A following space is literally a space. %(refname)
refers to the ref name. The full name of a remote tracking branch is like refs/remotes/origin/foo
. :lstrip=2
suppresses the left 2 parts refs
and remotes
.
See git for-each-ref for more.
Upvotes: 2
Reputation: 181
I got bit of answer but still not the concrete on:
Commands used : To List all branches :
git branch -r >>branchesList
List all Hashcode for branches :
for remote in git branch -r; do git rev-parse $remote ; done >> hascodeforbranches.txt*
Put it in an xl and u will have a mapping .
Upvotes: 0