Question

TL;DR

As described in this post, I changed a TFS changeset comment. How can I get this to be reflected in the corresponding Git commit in my local Git repository, using Git-Tfs?

Verbose version

I'm a Git-Tfs user. My workflow is such that I try to commit extremely small increments of code to my local Git repository ("one line change—tests green—commit" sort of thing) and push it up to the TFS server once I have a meaningful (but hopefully still small) changeset. Often this is after just one Git commit, but sometimes it is after several.

When checking several Git commits into TFS at once, Git-Tfs combines the Git commit messages as the default TFS check-in comment. So far so good. I usually tamper with them to make them a read more smoothly as a single changeset comment. But today I forgot to and checked in a message that would have been less than helpful to my TFS-using coworkers.

Okay, no big deal. I used TFS to edit the changeset comment to make it more coherent. However, I have not been able to get my local Git repository synced up with this change. This is not a big deal, because mainly I changed it for other people. However, I am curious to see if I can get it synced up.

What I've tried

I tried this, but the commit message is still what it was before I edited the changeset comment:

git reset --hard HEAD~
git tfs pull
Was it helpful?

Solution

How can I get this to be reflected in the corresponding Git commit in my local Git repository, using Git-Tfs?

you should understand that due to the fact of how git is build, you CAN'T modify a commit. Each git commit is "sealed" by its sha1.

The only thing that you can do is reset your tfs remote tfs/default to a previous state and fetch the tfs changesets again. I don't even understand what you want to achieve by resetting your local branch!?! This is always the remotes that reflect the commits of remote repositories and not local branches! git-tfs don't even care about your local branch. The only thing it is looking is the last fetched changeset in your tfs remote (based on the metadata git-tfs-id: written in the commit message of the fetched changeset).

There is a git-tfs command reset-remote to do this reset easily (and safely) with git-tfs since v0.19:

git tfs reset-remote HEAD~ #reset the tfs remote to fetch it again
git reset --hard HEAD~ #reset also the local branch to override a git-tfs optimisation when re-fetching changesets
git tfs pull #fetch tfs changesets again

PS:

When checking several Git commits into TFS at once, Git-Tfs combines the Git commit messages as the default TFS check-in comment. So far so good. I usually tamper with them to make them a read more smoothly as a single changeset comment.

If you want git-tfs to "mirror" your commit in TFS, perhaps you should think about using the git tfs rcheckin command...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top