网上有很多解决方案,比如https://blog.csdn.net/qldxsun/article/details/80398318

但是,要具体情况 具体分析。

 

我最近利用 GitKraken通过分支,定位BUG。但是忘记切换到当前最新分支。

我的每次提交都 建立了HEAD上了,所以远程提交 始终自己分支没有出现。

 

后来 网上找方案 切换 自己分支,突然 发现一天的开成果都没有了。好在同事鼎力帮助,找到了解决方案。

切换自己分支,逐个git merge到自己分支。最后终于全部还原,不用重写代码了。

当然,之前的命令行窗口没有关闭 也为这次解决提供了帮助。

MacBook-Pro:XNews2.0-ios chenshuliang$ git add .
MacBook-Pro:XNews2.0-ios chenshuliang$ git commit -m "Masonry框架引用 会导致"
  [恢复于 2019年11月13日 上午9:34:29]
Last login: Wed Nov 13 09:28:36 on ttys001
MacBook-Pro:XNews2.0-ios chenshuliang$ git commit -m "Masonry框架引用 BUG"
[detached HEAD 9746cca9] Masonry框架引用 BUG
 1 file changed, 63 insertions(+), 193 deletions(-)
MacBook-Pro:XNews2.0-ios chenshuliang$ git push origin xzy_test
Everything up-to-date
MacBook-Pro:XNews2.0-ios chenshuliang$ git add .
MacBook-Pro:XNews2.0-ios chenshuliang$ git commit -m "Masonry框架引用 IPHONEX "
[detached HEAD cc8816db] Masonry框架引用 IPHONEX
 1 file changed, 22 insertions(+), 22 deletions(-)
MacBook-Pro:XNews2.0-ios chenshuliang$ git push origin xzy_test
Everything up-to-date
MacBook-Pro:XNews2.0-ios chenshuliang$ ls
AIPIFlyMSC.framework			ios_distribution (4).cer
README.md				newXnews_inHouse.mobileprovision
XNEWS					pomodoSound.m4a
XNEWS.xcodeproj
MacBook-Pro:XNews2.0-ios chenshuliang$ git add .
MacBook-Pro:XNews2.0-ios chenshuliang$ git commit -m " BUG #5547 【测试环境】报道详情页部分模块末尾又出现了分割线"
[detached HEAD 25c67cbe]  BUG #5547 【测试环境】报道详情页部分模块末尾又出现了分割线
 2 files changed, 31 insertions(+), 11 deletions(-)
MacBook-Pro:XNews2.0-ios chenshuliang$ git push origin xzy_test
Everything up-to-date
MacBook-Pro:XNews2.0-ios chenshuliang$ git add .
MacBook-Pro:XNews2.0-ios chenshuliang$ git commit -m " BUG #5551 【测试环境】资源分配样式问题。"
[detached HEAD 2e9a503c]  BUG #5551 【测试环境】资源分配样式问题。
 2 files changed, 22 insertions(+), 1 deletion(-)
MacBook-Pro:XNews2.0-ios chenshuliang$ git push origin xzy_test
Everything up-to-date
MacBook-Pro:XNews2.0-ios chenshuliang$ git add .
MacBook-Pro:XNews2.0-ios chenshuliang$ git commit -m " BUG #5551 【测试环境】资源分配样式问题。 2"
[detached HEAD 086754db]  BUG #5551 【测试环境】资源分配样式问题。 2
 2 files changed, 16 insertions(+), 15 deletions(-)
MacBook-Pro:XNews2.0-ios chenshuliang$ git push origin xzy_test
Everything up-to-date
MacBook-Pro:XNews2.0-ios chenshuliang$ git add .
MacBook-Pro:XNews2.0-ios chenshuliang$ git commit -m " BUG #5555"
[detached HEAD 30d357cd]  BUG #5555
 12 files changed, 39 insertions(+)
MacBook-Pro:XNews2.0-ios chenshuliang$ git push origin xzy_test
Everything up-to-date
MacBook-Pro:XNews2.0-ios chenshuliang$ git add .
MacBook-Pro:XNews2.0-ios chenshuliang$ git commit -m "BUG #5553 【测试环境】资源分配时间选择优化。"
[detached HEAD 2f0040f4] BUG #5553 【测试环境】资源分配时间选择优化。
 3 files changed, 21 insertions(+), 3 deletions(-)
MacBook-Pro:XNews2.0-ios chenshuliang$ git push origin xzy_test
Everything up-to-date
MacBook-Pro:XNews2.0-ios chenshuliang$ ls
AIPIFlyMSC.framework			ios_distribution (4).cer
README.md				newXnews_inHouse.mobileprovision
XNEWS					pomodoSound.m4a
XNEWS.xcodeproj
MacBook-Pro:XNews2.0-ios chenshuliang$ pwd
/Users/chenshuliang/Documents/tiberxWork/XNews2.0-ios
MacBook-Pro:XNews2.0-ios chenshuliang$ git add .
MacBook-Pro:XNews2.0-ios chenshuliang$ git commit -m "tijiao"
HEAD detached from c971af34
nothing to commit, working tree clean
MacBook-Pro:XNews2.0-ios chenshuliang$ git push origin xzy_test
Everything up-to-date
MacBook-Pro:XNews2.0-ios chenshuliang$ git push origin xzy_test
Everything up-to-date
MacBook-Pro:XNews2.0-ios chenshuliang$ git commit -m "msg"
HEAD detached from c971af34
nothing to commit, working tree clean
MacBook-Pro:XNews2.0-ios chenshuliang$ git push
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push origin HEAD:<name-of-remote-branch>

MacBook-Pro:XNews2.0-ios chenshuliang$ git branch -a
* (HEAD detached from c971af34)
  master
  test
  xzy_test
  remotes/origin/1.82
  remotes/origin/HEAD -> origin/master
  remotes/origin/aspera
  remotes/origin/dsx_test
  remotes/origin/master
  remotes/origin/releaseTest
  remotes/origin/test
  remotes/origin/xzy_test
  remotes/origin/开发涮选
  remotes/origin/语音转文字开发
MacBook-Pro:XNews2.0-ios chenshuliang$ git checkout xzy_test
Warning: you are leaving 7 commits behind, not connected to
any of your branches:

  2f0040f4 BUG #5553 【测试环境】资源分配时间选择优化。
  30d357cd  BUG #5555
  086754db  BUG #5551 【测试环境】资源分配样式问题。 2
  2e9a503c  BUG #5551 【测试环境】资源分配样式问题。
 ... and 3 more.

If you want to keep them by creating a new branch, this may be a good time
to do so with:

 git branch <new-branch-name> 2f0040f4

Switched to branch 'xzy_test'
Your branch is up to date with 'origin/xzy_test'.
MacBook-Pro:XNews2.0-ios chenshuliang$ git branch -a
  master
  test
* xzy_test
  remotes/origin/1.82
  remotes/origin/HEAD -> origin/master
  remotes/origin/aspera
  remotes/origin/dsx_test
  remotes/origin/master
  remotes/origin/releaseTest
  remotes/origin/test
  remotes/origin/xzy_test
  remotes/origin/开发涮选
  remotes/origin/语音转文字开发
MacBook-Pro:XNews2.0-ios chenshuliang$ git add .
MacBook-Pro:XNews2.0-ios chenshuliang$ git commit -m "tijiao 2"
On branch xzy_test
Your branch is up to date with 'origin/xzy_test'.

nothing to commit, working tree clean
MacBook-Pro:XNews2.0-ios chenshuliang$ git push origin xzy_test
Everything up-to-date
MacBook-Pro:XNews2.0-ios chenshuliang$ git check out (HEAD detached from c971af34)
-bash: syntax error near unexpected token `('
MacBook-Pro:XNews2.0-ios chenshuliang$ git checkout (HEAD detached from c971af34)
-bash: syntax error near unexpected token `('
MacBook-Pro:XNews2.0-ios chenshuliang$ git checkout c971af34
Note: checking out 'c971af34'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at c971af34 直播界面 Ios 点击切换画面,无法切换画面,且演播室画面会消失 5 排查原因

具体操作如下:

MacBook-Pro:XNews2.0-ios chenshuliang$ git checkout xzy_test
Switched to branch 'xzy_test'
Your branch is up to date with 'origin/xzy_test'.
MacBook-Pro:XNews2.0-ios chenshuliang$ git merge 9746cca9
Updating c971af34..9746cca9
Fast-forward
 .../Controller/SMGLiveRoomController.m"            | 256 +++++----------------
 1 file changed, 63 insertions(+), 193 deletions(-)
MacBook-Pro:XNews2.0-ios chenshuliang$ git merge cc8816db
Updating 9746cca9..cc8816db
Fast-forward
 .../Controller/SMGLiveRoomController.m"            | 44 +++++++++++-----------
 1 file changed, 22 insertions(+), 22 deletions(-)
MacBook-Pro:XNews2.0-ios chenshuliang$ git merge 25c67cbe
Updating cc8816db..25c67cbe
Fast-forward
 .../View/SMTReportDetailHistoryCell.m"             | 13 ++++++++++
 .../View/SMTReportDetailManuCell.m"                | 29 ++++++++++++++--------
 2 files changed, 31 insertions(+), 11 deletions(-)
MacBook-Pro:XNews2.0-ios chenshuliang$ git merge 2e9a503c
Updating 25c67cbe..2e9a503c
Fast-forward
 .../Controller/SMTResourceController.m"              |  3 ++-
 .../View/SMTResourceBottomView.m"                    | 20 ++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
MacBook-Pro:XNews2.0-ios chenshuliang$ git merge 086754db
Updating 2e9a503c..086754db
Fast-forward
 .../Controller/SMTResourceDaiController.m"               | 16 +++++++++++++++-
 .../View/SMTResourceBottomView.m"                        | 15 +--------------
 2 files changed, 16 insertions(+), 15 deletions(-)
MacBook-Pro:XNews2.0-ios chenshuliang$ git merge 30d357cd
Updating 086754db..30d357cd
Fast-forward
 .../Controller/SMTReportDetailController.m"                          | 4 ++++
 .../Controller/SMTMyClueController.m"                                | 3 +++
 .../\346\224\266\345\275\225/Controller/SMTIncludelistController.m"  | 3 +++
 .../Controller/SMTMaterialDetailController.m"                        | 3 +++
 .../Controller/SMTCreateTopicController.m"                           | 3 +++
 .../Controller/SMTTopicDetailController.m"                           | 3 +++
 .../Controller/SMTTaskAuditController.m"                             | 3 +++
 .../Controller/SMTCreateInterviewController.m"                       | 3 +++
 .../Controller/SMTDeviceListController.m"                            | 3 +++
 .../Controller/SMTInterviewTopicController.m"                        | 5 +++++
 .../Controller/SMTReporterListController.m"                          | 3 +++
 .../Controller/SMTInterviewDetailController.m"                       | 3 +++
 12 files changed, 39 insertions(+)
MacBook-Pro:XNews2.0-ios chenshuliang$ git merge 2f0040f4
Updating 30d357cd..2f0040f4
Fast-forward
 XNEWS.xcodeproj/project.pbxproj                                |  4 ++--
 .../Controller/SMTResourceController.m"                        | 10 +++++++++-
 .../View/SSMTDatePickerView.m"                                 | 10 ++++++++++
 3 files changed, 21 insertions(+), 3 deletions(-)
MacBook-Pro:XNews2.0-ios chenshuliang$ git merge c971af34
Already up to date.
MacBook-Pro:XNews2.0-ios chenshuliang$ git log
commit 2f0040f46651cbdbd9481db5397fea6c0cceedcc (HEAD -> xzy_test)
Author: xuzhengyu <tiberx@smg.cn>
Date:   Wed Nov 13 14:16:56 2019 +0800

    BUG #5553 【测试环境】资源分配时间选择优化。

commit 30d357cd5e78c1c44b741941460d75d22268138f
Author: xuzhengyu <tiberx@smg.cn>
Date:   Wed Nov 13 14:03:07 2019 +0800

     BUG #5555

commit 086754db8d6d0be28c990928d791f16397b9ae96
Author: xuzhengyu <tiberx@smg.cn>
Date:   Wed Nov 13 13:40:26 2019 +0800

     BUG #5551 【测试环境】资源分配样式问题。 2

commit 2e9a503c49e0e8b4323a409baec0d47622f5fe12
Author: xuzhengyu <tiberx@smg.cn>
Date:   Wed Nov 13 13:23:12 2019 +0800

     BUG #5551 【测试环境】资源分配样式问题。

commit 25c67cbe83fac9250b99645c829351da929d4726
Author: xuzhengyu <tiberx@smg.cn>
Date:   Wed Nov 13 11:17:23 2019 +0800

     BUG #5547 【测试环境】报道详情页部分模块末尾又出现了分割线

commit cc8816dbe1d8ff5c5d9643a5c883142abcf7d706
Author: xuzhengyu <tiberx@smg.cn>
Date:   Wed Nov 13 09:53:08 2019 +0800

    Masonry框架引用 IPHONEX

commit 9746cca91cab9601ace3fa1998ca08d541940fd8
Author: xuzhengyu <tiberx@smg.cn>
Date:   Wed Nov 13 09:35:00 2019 +0800

    Masonry框架引用 BUG

commit c971af3435d502e7387a977a360317d17902e4e6 (origin/xzy_test)
Author: xuzhengyu <tiberx@smg.cn>
Date:   Tue Nov 12 14:24:32 2019 +0800

    直播界面 Ios 点击切换画面,无法切换画面,且演播室画面会消失 5 排查原因

commit 78770dc75801ec47cd432d52fba42a26f227660c
Author: xuzhengyu <tiberx@smg.cn>
Date:   Tue Nov 12 11:42:53 2019 +0800

MacBook-Pro:XNews2.0-ios chenshuliang$ git branch -a
  master
  test
* xzy_test
  remotes/origin/1.82
  remotes/origin/HEAD -> origin/master
  remotes/origin/aspera
  remotes/origin/dsx_test
  remotes/origin/master
  remotes/origin/releaseTest
  remotes/origin/test
  remotes/origin/xzy_test
  remotes/origin/开发涮选
  remotes/origin/语音转文字开发
MacBook-Pro:XNews2.0-ios chenshuliang$ git status
On branch xzy_test
Your branch is ahead of 'origin/xzy_test' by 7 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
MacBook-Pro:XNews2.0-ios chenshuliang$ git push origin xzy_test
Enumerating objects: 144, done.
Counting objects: 100% (144/144), done.
Delta compression using up to 8 threads
Compressing objects: 100% (97/97), done.
Writing objects: 100% (100/100), 28.52 KiB | 3.17 MiB/s, done.
Total 100 (delta 69), reused 0 (delta 0)
remote: Resolving deltas: 100% (69/69), completed with 31 local objects.
remote: 
remote: To create a merge request for xzy_test, visit:
remote:   http://gitlab.smgtech.net/jishubu/XNews2.0-ios/merge_requests/new?merge_request%5Bsource_branch%5D=xzy_test
remote: 
To gitlab.smgtech.net:jishubu/XNews2.0-ios.git
   c971af34..2f0040f4  xzy_test -> xzy_test
MacBook-Pro:XNews2.0-ios chenshuliang$ 

这样 就全部恢复了。

这就是团队开发的力量。我相信 软件开发的 个人英雄主义时代过去了。今后IT开发人员 一定要情商高 善于团队沟通  和协作  才能保证软件开发的质量。

 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐