我怎样才能用git-tfs清理破损的历史记录 [英] How can I clean up a broken history with git-tfs

查看:295
本文介绍了我怎样才能用git-tfs清理破损的历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定我是如何设法进入这个状态(*)的,但是我的tfs / default远程分支中有一些不存在于TFS中的提交,所以我想摆脱它们。因此,我的历史记录如下所示:

  A  -  B  -  C  -  D tfs / default 

...但是提交B和C实际上并不是TFS中的变更集。因此,当我检查tfs / default时,由于提交B和C,我与TFS不同步。



我想我可以修复它,如果我可以以某种方式将tfs / default remote重置为A,并执行另一个git tfs fetch以结束实际历史记录:

  A  -  D tfs / default 

但我不知道该怎么做?






*)如果它有什么区别,我认为它涉及在B和C上使用git tfs shelve,可能后跟一些提交和git tfs pull。但我不确定。

解决方案

是的,你有一半的答案!您应该将 tfs / default 重置为上一步并获取。在git中没有办法做到这一点(如果我知道的话),因为这不是正常的情况,但我们仍然可以通过编辑git文件来做到这一点......很简单!



如果您确定不想保留 B C 提交(否则将它们保存为临时文件通过创建一个本地分支),只需执行以下操作:




  • 进入您的 .git 文件夹并查找文件 / refs / remotes / tfs / default

  • 编辑文件并替换文件中的sha与$ A

  • 从tfs提取



那应该是好的!

编辑:也可以用命令行 git update-ref tfs / default SHAofcommitA


I'm not sure how I managed to get into this state(*), but I've got some commits in my tfs/default remote branch that don't exist in TFS, so I want to get rid of them. So my history looks like this:

A--B--C--D tfs/default

... but commits B and C aren't actually changesets in TFS. As a result, when I checkout tfs/default I am out of sync with TFS because of commits B and C. Not good.

I figured I could fix it if I could somehow reset the tfs/default remote to A and do another "git tfs fetch" to end up with the actual history:

A--D tfs/default

but I'm not sure how to do that?


*) If it makes any difference, I think it involved using "git tfs shelve" on B and C, maybe followed by some commits and a "git tfs pull". But I'm not sure.

解决方案

Yes, you've got half of the answer! You should reset the tfs/default to a previous step and fetch. There is no way to do that in git (if I know well) because that's not a normal case but we could still do that by editing git files... it's easy!

If you are sure that you don't want to keep the B and C commits (otherwise save them temporary by creating a local branch), just do the following:

  • Go into your .git folder and look for the file /refs/remotes/tfs/default
  • edit the file and replace the sha in the file with the sha of commit A
  • fetch from tfs

And that should be good!

edit: can also be done with command line git update-ref tfs/default SHAofcommitA

这篇关于我怎样才能用git-tfs清理破损的历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆