1

The thing is that 4 of my team of 6 are beginners with git, so even though we told them to not work with the master branch directly, they did it.

Here´s what happened:

enter image description here

Before the blue line (to the side of the graph), almost everything was commited to the master branch directly, except for one branch, represented by its rose color.

As you can see, is a mess, I think they commited without pulling beforehand (yellow lines), so Git tried to make sense of it and merge those changes (green lines).

Is there any way to make this past changes linear?

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • The problem is that the damage is already done, because this history has been pushed to the server and downloaded to everyone's individual copy of the repo. The simplest thing at this point would be to have everyone except maybe you throw their clone away. Then you rearrange the history using rebase / cherry-pick or whatever you like, force it up to the server, and have everyone clone that freshly. – matt Apr 25 '20 at 13:25
  • Your description of what happened looks wrong to me, by the way. It looks to me like this is a perfectly good history except for a couple of glitches. Some seems to have started with an orphan branch...? And some people committed directly to `master`. But otherwise everyone is just doing branch and merge, which is fine. That sort of railroad-siding picture is just the way it ought to look. Some people appear to be re-using branches; that's not totally terrible, but it's better policy for beginners to delete your branch after merging and make a new branch. – matt Apr 25 '20 at 13:31
  • That said, the usual thing is to work on `develop`, not `master`. So the blue in your picture should be `develop`, not `master`. That way you can squash onto `master` from time to time and it will have an independent linear development, with only `develop` preserving the history. – matt Apr 25 '20 at 13:34
  • Does this answer your question? [How do I trivially linearize my git history?](https://stackoverflow.com/questions/17988099/how-do-i-trivially-linearize-my-git-history) – Joe Apr 25 '20 at 13:40
  • It seems like orphan branches indeed, I'm guessing this how Git tried to make sense of the changes rather that an explicit command to do so (I've already talked with my peers), because I'm 100% sure that (for example), the commit in the orange "orphan branch" was made originally in the master branch and just pushed, without pulling. the same happened blue commit (The one with the yellow mark, just after the orange one). –  Apr 25 '20 at 13:43
  • @Joe I'm going to try it. Thanks. –  Apr 25 '20 at 13:52
  • If you use GitHub, you might consider *not* allowing your newbies to merge at all (use GitHub's "protected branches" feature and/or make them create forks). If you don't use GitHub, consider preventing your newbies from pushing directly in some other way. That way you can rebase their commits into your own preferred work-flow. – torek Apr 25 '20 at 23:03
  • Yeah I will consider this for later projects. –  Apr 25 '20 at 23:31
  • I tried differents things, but nothing seems to work, thank you all for your replies though. This more a visual thing than functional thing, so I'm just gonna leave it as it is right now. –  Apr 25 '20 at 23:34

0 Answers0