如何得到最近提交的Git分支列表? - How can I get a list of Git branches, ordered by most recent commit?

問題:

I want to get a list of all the branches in a Git repository with the "freshest" branches at the top, where the "freshest" branch is the one that's been committed to most recently (and is, therefore, more likely to be one I want to pay attention to). 我想獲得一個Git存儲庫中全部分支的列表,頂部有「最新鮮」的分支,其中「最新鮮」的分支是最近提交的分支(所以,更多是一個分支)我想要注意)。 git

Is there a way I can use Git to either (a) sort the list of branches by latest commit, or (b) get a list of branches together with each one's last-commit date, in some kind of machine-readable format? 有沒有辦法能夠使用Git(a)經過最新提交對分支列表進行排序,或者(b)以某種機器可讀格式獲取分支列表以及每一個分支的最後提交日期? this

Worst case, I could always run git branch to get a list of all the branches, parse its output, and then git log -n 1 branchname --format=format:%ci for each one, to get each branch's commit date. 最糟糕的狀況是,我老是能夠運行git branch來獲取全部分支的列表,解析其輸出,而後git log -n 1 branchname --format=format:%ci爲每一個分支,以得到每一個分支的提交日期。 But this will run on a Windows box, where spinning up a new process is relatively expensive, so launching the Git executable once per branch could get slow if there are a lot of branches. 可是這將在Windows機器上運行,其中啓動新進程相對昂貴,所以若是有不少分支,每一個分支啓動Git可執行文件可能會變慢。 Is there a way to do all this with a single command? 有沒有辦法用一個命令完成全部這些? spa


解決方案:

參考一: https://stackoom.com/question/Llia/如何得到最近提交的Git分支列表
參考二: https://oldbug.net/q/Llia/How-can-I-get-a-list-of-Git-branches-ordered-by-most-recent-commit
相關文章
相關標籤/搜索