git 中 出现your current branch appears to be broken错误

git 中 出现your current branch appears to be broken错误

1.死机导致的 Git 错误

原因为:IDEA崩了,使用git log 命令时候提示标题中错误,git status 提示正常 。

2. 解决方案,修复 .git/refs/heads/分支名

2.1 查找 .git/logs/refs/heads/分支名, 打开这个文件

2.2 查找 .git/logs/refs/heads/分支名, 打开这个文件找到最后一次 commit 的 commit-id

711fe2d55860cf1fb6d5c2a8867363ef29b372e8 eaf57a1fdde86d985340a993ceb9beadb7cf11f3 yanglin1501804006 1593426173 +0800 commit: 整合半有缘的接口管理功能

这里的 commit-id 就是eaf57a1fdde86d985340a993ceb9beadb7cf11f3

2.3 用文本打开 ./git/refs/heads/分支名 , 将 commit-id 覆盖写入该文件

2.4 再次运行 git log, ok 正常了

git 中 出现your current branch appears to be broken错误_第1张图片

3. 正常提交代码

$ git status
On branch B#yanglin02
Your branch is ahead of ‘origin/B#yanglin02’ by 94 commits.
(use “git push” to publish your local commits)
nothing to commit, working tree clean

3.1 git branch -vv

git branch -vv

  • B#yanglin02 812065f01 [origin/B#yanglin02: ahead 94] Merge branch ‘B#zhoumei’ into ‘master’
    master 061f17dd2 [origin/master: behind 282] Merge branch ‘b#modify_all_svc_port’ into ‘master’

查看自己本地开发分支与远程分支关系

3.2 git push origin B#yanglin02

$ git push origin B#yanglin02
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: To create a merge request for B#yanglin02, visit:
remote: http://IP地址/TIAP/tiap/merge_requests/new?merge_request%5Bsource_branch%5D=B%23yanglin02
remote:
To [IP地址]:TIAP/tiap.git
eaf57a1fd…812065f01 B#yanglin02 -> B#yanglin02

3.3 git status

$ git status
On branch B#yanglin02
Your branch is up to date with ‘origin/B#yanglin02’.
nothing to commit, working tree clean

这样就正常啦!

4.如何重现 your current branch appears to be broken

创建一个测试环境:

/ 初始环境
// 提交了2次
git init
echo “Spring的思念” > hehe.txt
git add .
git commit -m “init”
echo “Vue的重生” >> hehe.txt
git add .
git commit -m “add a words”

5.修改 ./git/refs/heads/master

重现该问题很简单,就是将./git/refs/heads/ 下的master文件更改/替换。

$ cat ./.git/refs/heads/master
9eeeab031b8f57285bbcdfaee5eeced70b11756343f
$ echo “haihia, you are broken” > ./.git/refs/heads/master
$ git log
fatal: your current branch appears to be broken

出现这个问题,可以使用上边的方法进行修复。

下面这个脚本的含义就是 找到最后一行中的第二个 commit-id 然后写入 ./.git/refs/heads/master中

$ tail -n 1 ./.git/logs/refs/heads/master | awk ‘{print $2}’ > ./.git/refs/heads/master
$ git log

6. error: bad signature fatal: index file corrupt

如何修复的步骤:

6.1 删除 .git/index 文件

6.2 git reset 这个命令在执行过程中, 会重建 index 文件

如此操作就正常了~

7.如何重现 bad signature fatal: index file corrupt

同样的道理,将 .git/index 文件中内容更改即可复现。

你可能感兴趣的:(git)