Hacker News new | ask | show | jobs
by hnrodey 1687 days ago
Man, I really feel for people who struggle with Git. I should know - I was one of them many years ago.

Many day-to-day problems with Git all have something in common which is that the user has got their repo in to some state they do not understand. And most times (as comments have mentioned) they don't even know what they did to get themselves in their current pickle.

The quickest path to resolution is usually a hard reset to the server version of the branch then restore the commit(s) that user had made.

If you have pending changes then handle those first. It doesn't matter much what they are just commit or stash. If committing don't even think about the message just use `wip commit`. Finally, note every commit id that has your work you want to keep around. Might be 1, 5 or 20 commits.

Okay, now hard reset.

`git reset --hard <remote_name>/<branch_name>`

Great, now you're at an acceptable state.

Finally, restore your previous commits use cherry-pick or `git stash apply` to get your stuff modified.

If cherry pick then it's `git cherry-pick <sha_oldest> <sha_next_oldest> ....`

On to the next problem...

1 comments

Here is a crazy idea:

1. Commit your your local changes, squash if you want.

2. Do a pull --rebase

3. Push

If this doesn't work, it's your own fault. Start over.