Author Topic: More GIT help. Mike? TGM?  (Read 1378 times)

micah

  • A man on the Internet.
  • Jackass In Charge
  • Posts: 6508
  • Karma: +55/-55
  • Good man. Nixon's pro-war and pro-family.
    • micahj.com
More GIT help. Mike? TGM?
« on: December 21, 2015, 10:47:24 PM »
I pushed a bunch of commits last night to a feature branch. I was out of the office working at a clients location on a different project so a helpful coworker jumped in on my project back at the office but he apparently didn't do a pull first so he was working on the same files but in a state from before I made those dozen or so commits the previous night.

He then pushed his shit back to the origin repo and that reversed everything I had done.  So now, if I pull his commits I lose my work but if I push my stuff again, we lose anything he did today.

What do we do?

"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

tgm

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3647
  • Karma: +46/-18
Re: More GIT help. Mike? TGM?
« Reply #1 on: December 22, 2015, 12:00:34 AM »
This one might get tricky. Your work won't be gone. It'll be in the reflog but getting it um. Probably best to figure out what commit you left off of and revert to that. Then replay his commits on top of that. I'd have to try and setup the scenario to figure it out but it will likely involve doing a git reset --soft. I'd probably brute force it a bit since I'm not a git master and clone twice/diff the two commits and figure out a patch.
This signature intentionally left blank.

tgm

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3647
  • Karma: +46/-18
Re: More GIT help. Mike? TGM?
« Reply #2 on: December 22, 2015, 12:13:51 AM »
Did he force push on top or just a bad merge?
This signature intentionally left blank.

Mike

  • Ass Wipe
  • Posts: 11951
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: More GIT help. Mike? TGM?
« Reply #3 on: December 22, 2015, 01:45:35 AM »
Sounds like there are three repos in play here:  yours, coworkers, and servers.  It also sounds like yours hasn't be modified yet.

Ok, first thing: go to your repo and do git branch mybranch_backup  Call it whatever you want.  What this does is create a new branch with the same head as your current branch.  Not needed but it is a ton easier that doing log, copying the SHA to some other location, and copying it back later.  Instead you've got a nice name for it.  I'd recommend doing something similar with the server's branch.  git fetch (not pull), git branch fucktards_backup origin/branch (check the order of the last two params before using).  Now you've got backups of your and the server's branch

Next: pull fucktard's changes.  Most likely you are gonna get merge conflicts.  If you can resolve it then glorious day you are probably done.  If not, well that's the fun part.  You've got some options.  You can always reset the branch and then step forward while you resolve conflicts.

You are probably a lot less screwed than you think.  You just need to sit down and sketch out the graph.  You can think about it as being two feature branches where one branched before updating (which happens a lot).

tgm

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3647
  • Karma: +46/-18
Re: More GIT help. Mike? TGM?
« Reply #4 on: December 22, 2015, 10:23:44 AM »
Just out of curiousity micah, what's your typical cycle of using git? e.g. pull, branch, push, pull-request, etc. It might help to tweak the process to minimize this kind of stuff. Recently I've taken to branching and rebase until I push my branch and do a pull request. That seems to keep merge conflicts to a minimum and usually easier to resolve.

And if you have the time I highly recommend watching this talk:
https://www.youtube.com/watch?v=PJzwoEAP9GQ

It's from a guy I know locally here and I think it's pretty good for general git understanding.
This signature intentionally left blank.

tgm

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3647
  • Karma: +46/-18
Re: More GIT help. Mike? TGM?
« Reply #5 on: December 22, 2015, 10:30:55 AM »
Also I really like using 'tig' for my tool to view the git history.
This signature intentionally left blank.

Perspective

  • badfish
  • Jackass In Charge
  • Posts: 4997
  • Karma: +63/-22
    • http://jeff.bagu.org
Re: More GIT help. Mike? TGM?
« Reply #6 on: December 22, 2015, 10:38:18 AM »
Do you want your stuff in master? Start with master and cherry pick your commits in.

Mike

  • Ass Wipe
  • Posts: 11951
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: More GIT help. Mike? TGM?
« Reply #7 on: December 22, 2015, 11:34:32 AM »
We do feature branches for everything combined with GitHub PRs.  We get conflicts from time to time but they are generally pretty minor.  The area we are working on right now is using integration branches for big projects.  Essentially a big feature branch that smaller feature branches branch off of and merge back into (with PRs).  When the project is ready for production then the integration branch is merged in.  Working pretty well so far, just some human behavioral issues that are easily spotted and addressed.

I also setup protection for our master branch on GitHub.  Now no one can force push to it, it can't be deleted, and non-admins have to have a unit test passing PR that is up-to-date in order to merge into master.

Just remember that git is all about the cheap branching and merging so use it.

Mike

  • Ass Wipe
  • Posts: 11951
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: More GIT help. Mike? TGM?
« Reply #8 on: December 22, 2015, 11:51:57 AM »
Oh and since my brain is now in git mode here is something very useful:
git add -p Interactive adding of diff segments.  You can stage parts of your change set.  You can even go in and edit the diff (helpful for quick typo fixes when reviewing your changes)

git checkout -p Like the above but in reverse.  Removes changes from your working tree.

Perspective

  • badfish
  • Jackass In Charge
  • Posts: 4997
  • Karma: +63/-22
    • http://jeff.bagu.org
Re: More GIT help. Mike? TGM?
« Reply #9 on: December 22, 2015, 02:23:36 PM »
I just magit in emacs, it lets you add diff hunks or even split them so you can stage line by line. Really useful.

Mike

  • Ass Wipe
  • Posts: 11951
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: More GIT help. Mike? TGM?
« Reply #10 on: December 22, 2015, 03:10:32 PM »
So a wrapper for add -p

micah

  • A man on the Internet.
  • Jackass In Charge
  • Posts: 6508
  • Karma: +55/-55
  • Good man. Nixon's pro-war and pro-family.
    • micahj.com
Re: More GIT help. Mike? TGM?
« Reply #11 on: December 22, 2015, 08:39:37 PM »
Thanks guys for the lively thread...

I was working off site again today and didn't get to touch this project (I'm just starting back up from home tonight).  My coworker ended up reverting back to what I had done, then re-applying his changes and making a few more.  So its all squared away.

The normal process for any changes is to create a feature branch off of dev.  Anyone who needs to work on that feature clones it from the remote repo (we use beanstalkapp.com but might be switching to bitbucket soon).  If more than one person is working on something, we try and keep track of who's doing what, but the rule of thumb is to do a pull from the remote before working and push commits fairly regularly.

Not sure where that broke down this time.

We usually depoly the feature branch to a development domain for QA before merging it back into the main dev branch.  Once a feature is merged to DEV that gets merged to Master and deployed to production.  There really isn't an actual need for the dev branch, other than a safety net to make sure hot fixes don't go straight to production without a quick review.

"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

Perspective

  • badfish
  • Jackass In Charge
  • Posts: 4997
  • Karma: +63/-22
    • http://jeff.bagu.org
Re: More GIT help. Mike? TGM?
« Reply #12 on: December 26, 2015, 09:04:42 PM »
The dev branch is a good idea since it has the same commit history as what will go into master. Two features branches might be good on their own, but when you message them both it could introduce a bug. Merging to a dev branch first will catch that before it goes live.

Mike

  • Ass Wipe
  • Posts: 11951
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: More GIT help. Mike? TGM?
« Reply #13 on: December 26, 2015, 10:32:21 PM »
dev branches are good if EVERY change will make its way to master.  Our dev branch isn't that setup that way so there are abandoned features and other cruft in it.  We've had to rebranch it before and are on the verge of doing it again.

What I'm moving us towards now is a system where we can easily spawn new testing environments on a feature/project basis and update them as we go.

Feature branch merge bug introductions seem to be more theory than practice.  I've yet to see it on finished features.  It is pretty simple to mitigate them through unit tests, requiring feature branches to be up-to-date and passing before merging, and communication.