2

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.

Anders
  • 544
  • 2
  • 8

1 Answers1

2

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

Philippe
  • 28,207
  • 6
  • 54
  • 78
  • Hmm wouldn't just `git reset --hard SHAofcommitA && git fetch` suffice ? As far as I know thats the proper way. – Learath2 Jun 24 '13 at 20:30
  • 1
    No, I don't think because he wants to move a remote managed by git-tfs and not a git branch... – Philippe Jun 24 '13 at 21:30
  • but `git rev-update tfs/default SHAofcommitA` would have worked – Philippe Sep 19 '13 at 22:36
  • @Phillipe: I think you mean `git update-ref tfs/default $SHA1`. rev-update is not a git command. And yes - update-ref is the correct way to edit the ref file. – patthoyts Sep 20 '13 at 08:40