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
来源:https://stackoverflow.com/questions/17279814/how-can-i-clean-up-a-broken-history-with-git-tfs