2

I've recently moved from svn to git, and I'm now wondering how I can generate a list of commits sorted by the date they are pushed to the repository.
Let's say you have cloned origin/master at a given date, with this list you would know exactly which commit you have pulled.

I've read many threads (like this, or this, even this) explaining git parenting system. At some point, I thought I could use git log together with the -m --first-parent option.

However looking at our existing merges, the first parent seems to be mixed up many times (ie. we have foxtrot merges), making it impossible to follow origin/master.

Now I'm wondering: is my request even possible?

I've seen that Team Foundation Server / VSTS displays a list of pushes that is exactly what I want. Merges will show the messages from corresponding commits.
They even have an API for that. However, I'd like to avoid relying on them to generate my push-list.enter image description here

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
Julien M
  • 657
  • 3
  • 10
  • 40

1 Answers1

1

VSTS logs additional meta-data on the server side. This meta-data is not available in your local repository. In addition to standard Git-commit-data, it logs:

  • Pusher (the user account of the user performing the push)
  • and the exact time of that push
  • as well as the commits that were added to the repo as part of that push.

This information is not available in your local git repository. Looking at it from a distributed version control position, it's also a bit strange to rely on this meta-data, because it could have been pushed to many different repositories at many different times. And it may have been pushed from one repository to another.

Only in a blessed repository setup (which role the TFS/VSTS server is performing in your setup), can that server keep track of what was pushed to that server.

Hence, you'll need to rely on the REST API provided by TFS/VSTS.

As to untangling old foxtrot merges:

What should I do about the pre-existing foxtrot merges that have infected my git repo? Nothing. Leave them. Unless you’re one of those antisocial people that rewrites master. Then go nuts. Actually, please don’t.

But if you're really inclined to untangling:

I accidentally created a foxtrot merge, but I haven’t pushed it. How can I fix it? You have three possible remedies:

  1. Simple rebase:
    enter image description here
  2. Reverse your earlier merge to make origin/master the first-parent: enter image description here
  3. Create a 2nd merge commit after the foxtrot merge to preserve origin/master’s –first-parent relation. enter image description here

But please don’t do #3, because the final result is called a “Portuguese man o’ war merge,” and those guys are even worse than foxtrot merges.

Source: https://developer.atlassian.com/blog/2016/04/stop-foxtrots-now/

Community
  • 1
  • 1
jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • I've seen users building their push history using git log -m --first-parent I suppose that's my only option if I want to avoid relying on the REST API, correct? Which leads to my second question: can I fix existing foxtrot merges? – Julien M Nov 24 '17 at 14:02
  • Yes then tracking back through first parent is your only option. And as far as I know you can't fix the foxtrot merges without rewriting history and force pushing the repo with a fixed up version. – jessehouwing Nov 24 '17 at 14:07
  • Thank you. Would you have any good read that would tell me more about rewriting history? I only have a couple recent merges to fix. – Julien M Nov 24 '17 at 14:09
  • Updated with reverse instructions. Though the general advice is: **don't**. If you have multiple consecutive foxtrot merges, you'll have to work your way back merge by merge until your local repo is back in a good state. – jessehouwing Nov 24 '17 at 16:19
  • I had read that tutorial already, however you describe how to revert a foxtrot merge that has not yet been pushed. Which is not my case. – Julien M Nov 24 '17 at 16:47
  • End with `git push -f`, which is why untangling after push is generally a bad idea. When doing something like this all other contributors will have to rebate their work or they're in trouble. – jessehouwing Nov 24 '17 at 16:54
  • I've been trying locally and ended up doing `git rebase --onto old-hash old-hash` `git push origin +master`and when replaying, rebase cleans up my merge automagically. Since you are a VSTS expert, do you confirm I can run this command against Microsoft's git repository? – Julien M Nov 24 '17 at 22:36
  • VSTS git is just git. It may require special permissions to force push the branch you're trying to clean up, but if you have those it will happily do it for you. – jessehouwing Nov 24 '17 at 22:59
  • I have those permissions. But as you said VSTS stores meta-data so it is not 'just git'. Will it recreates the pushes or will it break? – Julien M Nov 24 '17 at 23:39
  • From a server perspective you're doing one new big push. It'll register as such. – jessehouwing Nov 25 '17 at 07:44