Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
677 views
in Technique[技术] by (71.8m points)

git branch - How can I get a list of Git branches that I've recently checked out?

When moving between Git branches I sometimes forget the name of a branch I was recently on. How can I display a list of recently checked out branches/tags/commits in order of checkout?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Summary:

You can use Git's reflog to show recent movements in order of checkout: git reflog

Script:

Here's a script you can download and use via git recent from inside any Git repository: https://gist.github.com/jordan-brough/48e2803c0ffa6dc2e0bd

Usage:

$ (master) git recent -n 5

1) master  4) deleted-branch
2) stable  5) improve-everything
3) fun
Choose a branch: 2

$ (stable) …

See the gist for more details/options.

Details:

Here's essentially what the script does to make the reflog output more usable:

$ git reflog | egrep -io "moving from ([^[:space:]]+)" | awk '{ print $3 }' | awk ' !x[$0]++' | egrep -v '^[a-f0-9]{40}$' | head -n5
master
stable
fix-stuff
some-cool-feature
feature/improve-everything

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...