找到在git <no branch>中的commit

本文介绍了一种在未创建分支的情况下直接提交到master后如何找回这些提交的方法。通过使用`git fsck --lost-found`、`git fsck --unreachable`或`git log -g`等命令来定位裸commit,并提供了具体的步骤来创建新的分支。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


如果你也像我一样发生过在 <no branch>的git 环境中进行过
git commit
然后忘记新建branch,就
git checkout master
,这时要找到你那些commit
就要执行
git fsck --lost-found

git fsck --unreachable

git log -g
找到你在no branch上的<commit> 串,
之后
git checkout <commit>
git branch  <new branch>
就好了。
git branch --contains e49f53fcbe30b53e49983a5ba1f1dec36932a06c error: no such commit e49f53fcbe30b53e49983a5ba1f1dec36932a06c usage: git branch [<options>] [-r | -a] [--merged | --no-merged] or: git branch [<options>] [-l] [-f] <branch-name> [<start-point>] or: git branch [<options>] [-r] (-d | -D) <branch-name>... or: git branch [<options>] (-m | -M) [<old-branch>] <new-branch> or: git branch [<options>] (-c | -C) [<old-branch>] <new-branch> or: git branch [<options>] [-r | -a] [--points-at] or: git branch [<options>] [-r | -a] [--format] Generic options -v, --verbose show hash and subject, give twice for upstream branch -q, --quiet suppress informational messages -t, --track set up tracking mode (see git-pull(1)) -u, --set-upstream-to <upstream> change the upstream info --unset-upstream Unset the upstream info --color[=<when>] use colored output -r, --remotes act on remote-tracking branches --contains <commit> print only branches that contain the commit --no-contains <commit> print only branches that don't contain the commit --abbrev[=<n>] use <n> digits to display SHA-1s Specific git-branch actions: -a, --all list both remote-tracking and local branches -d, --delete delete fully merged branch -D delete branch (even if not merged) -m, --move move/rename a branch and its reflog -M move/rename a branch, even if target exists -c, --copy copy a branch and its reflog -C copy a branch, even if target exists --list list branch names -l, --create-reflog create the branch's reflog --edit-description edit the description for the branch -f, --force force creation, move/rename, deletion --merged <commit> print only branches that are merged --no-merged <commit> print only branches that are not merged --column[=<style>] list branches in columns --sort <key> field name to sort on --points-at <object> print only branches of the object -i, --ignore-case sorting and filtering are case insensitive --format <format> format to use for the output
03-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值