linux:git
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| linux:git [2026/01/09 19:32] – [ACCIDENTALLY COMITED ON MASTER] v1ctor | linux:git [2026/02/13 18:52] (current) – [SQUASH] v1ctor | ||
|---|---|---|---|
| Line 8: | Line 8: | ||
| // 3. Move your working directory to that branch | // 3. Move your working directory to that branch | ||
| </ | </ | ||
| + | --------------- | ||
| ==== DELETE REMOTE BRANCH ==== | ==== DELETE REMOTE BRANCH ==== | ||
| Line 21: | Line 21: | ||
| git push origin --delete < | git push origin --delete < | ||
| </ | </ | ||
| + | --------------- | ||
| ==== ACCIDENTALLY COMITED ON MASTER ==== | ==== ACCIDENTALLY COMITED ON MASTER ==== | ||
| Line 44: | Line 45: | ||
| git log --oneline master | git log --oneline master | ||
| </ | </ | ||
| + | --------------- | ||
| ==== SQUASH ==== | ==== SQUASH ==== | ||
| Line 49: | Line 51: | ||
| Scenario - you would like to " | Scenario - you would like to " | ||
| - | **Step 1** | + | **Step 1** - Find the **base commit** where your branch diverged from main |
| - | + | ||
| - | Find the **base commit** where your branch diverged from main | + | |
| <code bash> | <code bash> | ||
| git merge-base master HEAD | git merge-base master HEAD | ||
| </ | </ | ||
| - | **Step 2** | + | **Step 2** - Start interactive rebase from that commit: |
| - | + | ||
| - | Start interactive rebase from that commit: | + | |
| <code bash> | <code bash> | ||
| git rebase -i abc123 | git rebase -i abc123 | ||
| </ | </ | ||
| - | **Step 3** | + | **Step 3** - In editor which will open, change all but the first pick to squash or just s: |
| - | + | ||
| - | In editor which will open, change all but the first pick to squash or just s: | + | |
| <code bash> | <code bash> | ||
| pick abc123 My first commit | pick abc123 My first commit | ||
| Line 72: | Line 68: | ||
| </ | </ | ||
| - | **Step 4** | + | **Step 4** - Editor will open again for a commit message. Edit as you wish. |
| - | Editor will open again for a commit message. Edit as you wish. | + | **Step 5** - Push with force: |
| - | + | ||
| - | **Step 5** | + | |
| - | + | ||
| - | Push with force: | + | |
| <code bash> | <code bash> | ||
| git push --force | git push --force | ||
| </ | </ | ||
| - | **Step 6** | + | **Step 6** - When trying to pull after these changes, you might need to rebase: |
| - | + | ||
| - | When trying to pull after these changes, you might need to rebase: | + | |
| < | < | ||
| git config pull.rebase true | git config pull.rebase true | ||
| git pull | git pull | ||
| + | </ | ||
| + | |||
| + | ==== CHANGE COMMIT MESSAGE ==== | ||
| + | |||
| + | If the commit has been already pushed to the upstream, and it's the latest commit: | ||
| + | |||
| + | <code bash> | ||
| + | git commit --amend # edit the commit msg | ||
| + | git push --force | ||
| </ | </ | ||
linux/git.1767987167.txt.gz · Last modified: by v1ctor
