Skip to content

Commit

Permalink
feat: git reorder commits
Browse files Browse the repository at this point in the history
  • Loading branch information
allisonmachado committed Jul 3, 2024
1 parent 9988a3d commit 4560478
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions posts/git-cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ date: "2022-05-15"

This cheat sheet provides a quick overview of some time saving git commands. If you need more information or context, click the title of each section.

## [Merge last N commits](https://stackoverflow.com/questions/5189560/how-do-i-squash-my-last-n-commits-together)

```bash
$ git reset --soft "HEAD~n"
$ git commit -m "new commit message"
```

## [Change commit order](https://stackoverflow.com/a/58087338)

Here, 3 is the number of commits that need reordering:

```bash
$ git rebase -i HEAD~3
```

## [Reuse the previous commit message and also want to edit it](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt--cltcommitgt)

```bash
$ git commit -c HEAD
```

## [Avoid Rebase Hell](https://blog.oddbit.com/post/2019-06-17-avoid-rebase-hell-squashing-wi/)

```bash
Expand All @@ -25,13 +46,6 @@ $ git checkout --theirs ./path/to/file/or/directory
$ git checkout --ours ./path/to/file/or/directory
```

## [Merge last N commits](https://stackoverflow.com/questions/5189560/how-do-i-squash-my-last-n-commits-together)

```bash
$ git reset --soft "HEAD~n"
$ git commit -m "new commit message"
```

## [Push the current branch to its upstream by default](https://stackoverflow.com/questions/948354/default-behavior-of-git-push-without-a-branch-specified)

```bash
Expand Down Expand Up @@ -102,12 +116,6 @@ $ git commit --amend --author="Author Name <email@address.com>" --no-edit

The author name and email can be found using `git log`.

## [Reuse the previous commit message and also want to edit it](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt--cltcommitgt)

```bash
$ git commit -c HEAD
```

## [Restore local deleted branch](https://stackoverflow.com/a/4025983)

The commit hash should be known (maybe inspecting terminal log history)
Expand Down

0 comments on commit 4560478

Please sign in to comment.