Skip to content

Commit 410fda0

Browse files
committed
added post getting out of git hell
1 parent a806a68 commit 410fda0

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
layout: post
3+
title: Getting out of Git Hell
4+
date: 2023-05-07
5+
categories: [git]
6+
tags: [githell, ramble]
7+
---
8+
9+
The other day I found myself in the midst of A Bad Commit and the anger of other folks on the team - yeah yeah, I'll fix it. Normally if it was my own repo whee I don't care about the pristine commit history, i would script the PR and/or the branch and start over with a fresh update from master. However, that is just myself being lazy. Surely it can be fixed the right way.
10+
11+
## PROTIP
12+
13+
Before reading any blog posts or phoning in reinforcements, do this:
14+
15+
```
16+
git remote -v
17+
```
18+
19+
Different teams assign "origin" to different things. Some "its my master in my fork" or "its the master in the original repo" Just make sure where things are going before you start following directions. Don't ask me how I know.
20+
21+
## Digging
22+
23+
Here's how to fix a bad commit.
24+
25+
Work on a copy of your bad branch so you can change your mind later!
26+
27+
Get the sha of the last good point - lets all it `brisket`.
28+
29+
```
30+
git diff --name-only `brisket`
31+
```
32+
33+
Confirm those are the files that were added by accident
34+
35+
Armed with that knowledge lets remove files we don't want from the commit
36+
37+
```
38+
git reset `brisket` [file 1] [file 2]
39+
```
40+
41+
Now commit this !!!
42+
43+
```
44+
git commit -m "reset files that should not be"
45+
```
46+
47+
Then, do this
48+
49+
```
50+
git log --oneline
51+
```
52+
53+
We need to smoosh the commit so nobody can see our messup (I guess, with reflog there are no secrets but lets hope nobody is digging that hard)
54+
55+
```
56+
git rebase HEAD~2
57+
```
58+
59+
use `f for fixup`, discarding our stupid message about resetting files
60+
61+
git push origin myawesomebranch
62+
63+
(or whatever remote name you want) .. you may want to use force or I recently learned about `--force-with-lease` which might be good to learn to use.
64+
65+
I made this mostly as note to my future self when I foobar a commit but maybe it will help you.

0 commit comments

Comments
 (0)