git学习总结之fsck、reflog、恢复已删除分支

最新更新时间:2020年03月12日12:09:55

《猛戳-查看我的博客地图-总有你意想不到的惊喜》

本文内容:git常用命令

fsck

  • git fsck

fill system check 文件系统检查,用来对本地和远程仓库的一致性检查,dangling objects悬空对象
在悬空对象列表中,使用git show commitId查看悬空记录的详情,git merge commitId即可恢复

reflog

  • git reflog

reference log引用日志,查看本地本地的所有操作记录,每个分支上查看的结果一样,最早的一条记录是clone: from http://***.gitctrl+z退出查看模式

包含删除本地分支和远程分支的记录

  • 引用日志记录包含以下几种情况
  • pull
  • Fast-forward 快进
  • Merge made by the ‘recursive’ strategy. 递归合并策略
  • merge develop: Fast-forward
  • commit
  • commit (merge)
  • checkout
  • moving from master to master 分支名相同表示删除记录
  • moving from develop to master
  • moving from commit_id to branch_name
  • moving from branch_name to tag_name
  • merge branch_name
  • Fast-forward
  • Merge made by the ‘recursive’ strategy.
  • reset
  • moving to HEAD
  • moving to feature_camera
  • 恢复删除的远程分支

git reflog查看删除的远程分支操作的commit_id
git checkout -b recover_branch_name commit_id创建新分支方案一
git branch recover_branch_name HEAD@{number}创建新分支方案二
git push origin recover_branch_name提交到远程仓库

  • 以标准时间显示

git reflow --date=iso
70cb580 HEAD@{2020-02-25 15:14:31 +0800}: checkout: moving from master to master
不加--date=iso参数,则以标号显示,如下
70cb580 HEAD@{0}: checkout: moving from master to master

实用技巧

  • git branch -r还可以看到已经被删除的远程分支

git remote prune origin同步本地仓库和远程仓库信息,将远程仓库中已经被删除分支的信息,同步到本地仓库

  • 远程分支已经被删除,本地分支还存在

git remote prune origin同步本地仓库和远程仓库信息,即可删除本地分支
git pull -p

  • 查看远程仓库全部信息

git remote show origin可以看到远程仓库地址、远程分支、本地分支
git remote -v 查看远程仓库地址

  • 根据指定commit_id创建分支

git checkout -b new_branch_name commit_id

  • 根据指定tag_name创建分支

git checkout -b new_branch_name tag_name

  • 切换到指定的tag_name

git checkout tag_name

  • 切换到指定的commit_id

git checkout commit_id

  • 合并代码冲突详情
git checkout A
git merge B

<<<<<<< HEAD
  A分支的内容
=======
  B分支的内容
>>>>>>> B

恢复删除的本地和远程分支

删除的分支可以通过commitIdHEAD@{number}找回

  • 从代码仓库的activity栏查找已删除分支的 feature_name 的操作记录,可以查看到最后一次的commit记录,通过如下命令进行恢复

git checkout -b feature_delete_name commitId

  • 通过git reflog查看已删除分支的 feature_name 的操作记录,可以查看到最后一次的commitIdHEAD@{number}记录,通过如下命令进行恢复

git checkout -b feature_delete_name HEAD@{number}

仓库迁移

http://wangit.wsb.cn/fe/webview.git迁移到http://gitlab.wsb.cn/fe/webview.git,包括所有分支、标签和日志,操作步骤如下:

  • git clone --bare http://wangit.wsb.cn/fe/webview.git
  • cd webview.git
  • git push --mirror http://gitlab.wsb.cn/fe/webview.git

参考资料

感谢阅读,欢迎评论^-^

打赏我吧^-^

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章