Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
# git-tricks
Some git work commands. Keep in mind if you have any question what things are doing you can run
Some git work commands. Keep in mind if you have any question what things are doing. You can run
`man git` for the manual page of `git` and for example `man git-commit` for the manual page of `git commit` command.

## Add changes to the last commit
## Show History

Have a look on your git history
```
git log
```

or have a look on a dedicated commit:
```
git show <commit-SHA>
```

## Edit History

### Add changes to the last commit

If you like to add something to the last commit then you can run:
```shell
Expand All @@ -18,10 +32,11 @@ The `--amend` means that we append the last commit.

The `--no-edit` means that we don't want edit the commit message again.

## Add changes to an already existing commit, which is not the last one
### Add changes to an already existing commit, which is not the last one

1. Use `git stash` to store the changes you want to add.
2. Use `git rebase -i HEAD~10` (or however many commits back you want to see).
You can also jump back to a specific commit-SHA: `git rebase -i <commit-SHA>`
3. Mark the commit for edit by changing the word `pick` at the start of the line into `edit`. Don't delete the other lines as that would delete the commits.
4. Save the rebase file, and git will drop back to the shell and wait for you to fix that commit.
5. Pop the stash by using git stash pop
Expand All @@ -30,6 +45,8 @@ The `--no-edit` means that we don't want edit the commit message again.
8. Do a `git rebase --continue` which will rewrite the rest of your commits against the new one.
9. Repeat from step 2 onwards if you have marked more than one commit for edit.

## Others

## Delete merged branches on local machine

```shell
Expand Down