需求
查看哪些分支包含了對應文本內容。
1,當印象中只知道代碼的部分內容,但是卻找不到代碼文件的時候(往往代碼不在當前分支或者存在於歷史記錄中),此方法有效
根據內容查找git文件並顯示commitid
git grep "toQuestionList" $(git rev-list --all)
查找git倉庫文件中中包含字符串"toQuestionList",顯示結果如下
查看commitid屬於哪個分支
git branch --contains 4369d46d0c31641d1f994b4e90c9ea380f0eecf1 --all
其中紅色部分內容表示查詢到的分支名稱
獲取最新鮮的分支
git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'