比如通过git push origin :a_branch
删除的分支,或者在github网页上删除的branch,有办法查看删除branch的历史吗
比如通过git push origin :a_branch
删除的分支,或者在github网页上删除的branch,有办法查看删除branch的历史吗
刚找回一个很久之前被删除的分支,也是因为幸运。
之前尝试使用git reflog
命令,但是很不幸没找到这个分支对应的提交记录。
最后,是在sourceTree的远端origin里面找到了想要恢复的分支feature/recover_branch,最后在跳转到
里面找到分支对应的commit id
例如8888d814e
执行命令,恢复删除的分支,并推送到线上
# 根据commit id,本地新建分支
git checkout -b feature/recover_branch 8888d814e
# 推送到远端
git push origin
从Github找到的一篇Gist,恢复已经删除的commit,不知道是否有用
Oops! I accidentally deleted a local git branch, and I haven't pushed it to a remote server yet. The branch has several important commits, and it hasn't been merged with any other branches yet. How do I find the missing branch?
1. Create a list of all dangling or unreachable commits.
These commits are copied into
.git/lost-found/commit/
, and non-commit objects are copied into.git/lost-found/other/
.2. Print a list of commit messages for all commits in the lost and found.
3. Find your missing commit through the process of manual inspection (i.e. reading).
If you need more information on a commit, you can always use a more detailed log command, such as
git log -p --stat --color 9ae38fc
.4. Create a new branch with the missing commit as the branch head.