Squash some git pieces

This commit is contained in:
Angelos Chalaris
2023-05-23 23:32:49 +03:00
parent 076d5727c6
commit 36d24eda77
7 changed files with 74 additions and 82 deletions

View File

@ -1,5 +1,5 @@
--- ---
title: "Tip: Automate upstream branch creation" title: "Tip: Automate Git upstream branch creation"
shortTitle: Automate upstream branch creation shortTitle: Automate upstream branch creation
type: tip type: tip
language: git language: git

View File

@ -1,25 +0,0 @@
---
title: Edit the last commit
type: snippet
language: git
tags: [commit]
cover: tram-car
dateModified: 2021-04-13T21:10:59+03:00
---
Updates the last commit's contents without changing its message.
- Use `git commit --amend --no-edit` to add any staged changes to the last commit, without changing its message.
```shell
git commit --amend --no-edit
```
```shell
git add .
git commit -m "Fix the network bug"
# Edit or add files
git add .
git commit --amend --no-edit
# The last commit includes the edited/added files
```

View File

@ -0,0 +1,49 @@
---
title: Change the last commit's message or contents in Git
shortTitle: Amend last commit
type: story
language: git
tags: [commit]
author: chalarangelo
cover: greek-coffee
excerpt: Learn how to effortlesly amend the last commit's message or contents using Git and fix any mistakes you might have made.
dateModified: 2023-05-23T21:10:59+03:00
---
Have you ever wanted to change the last commit's message or contents? Maybe you forgot to add a file, or you misspelled something in the commit message. Whatever the reason, Git has you covered with the `--amend` option for the `git commit` command.
### Change the last commit's message
If you only want to change the last commit's message, you can use `--amend` and simply add the `-m` option followed by the new message. This will replace the last commit's message with the new one.
```shell
# Syntax: git commit --amend -m <message>
git add .
git commit -m "Fix the network bug"
# Creates the commit: 3050fc0 Fix network bug
git commit --amend -m "Fix the network bug"
# The last commit's message is now "Fix the network bug"
# This also changes its SHA-1 checksum
```
### Change the last commit's contents
If you want to change the last commit's contents, you can use `--amend` after staging the changes you want to add to the last commit. This will add any staged changes to the last commit, without changing its message.
If you want to keep the same commit message and only add the staged changes, you can use `--no-edit` to prevent Git from opening the default editor to change the commit message.
```shell
# Syntax: git commit --amend --no-edit
git add .
git commit -m "Fix the network bug"
# Creates the commit: 3050fc0 Fix network bug
# Edit or add files
git add .
git commit --amend --no-edit
# The last commit includes the edited/added files
# This also changes its SHA-1 checksum
```

View File

@ -1,23 +0,0 @@
---
title: Change the last commit's message
type: snippet
language: git
tags: [commit]
cover: greek-coffee
dateModified: 2021-04-13T21:10:59+03:00
---
Updates the last commit's message without changing its contents.
- Use `git commit --amend -m <message>` to replace the last commit's message with the new `<message>`.
```shell
git commit --amend -m <message>
```
```shell
git add .
git commit -m "Fix the newtork bug"
git commit --amend -m "Fix the network bug"
# The last commit's message is now "Fix the network bug"
```

View File

@ -1,22 +0,0 @@
---
title: View a short summary of commits without merge commits
type: snippet
language: git
tags: [repository,commit]
cover: river-flow
dateModified: 2021-04-13T21:10:59+03:00
---
Prints a short summary of all commits excluding merge commits.
- Use `git log --oneline --no-merges` to list a short summary of all commits without merge commits.
```shell
git log --oneline --no-merges
```
```shell
git log --oneline --no-merges
# 3050fc0de Fix network bug
# c191f90c7 Initial commit
```

View File

@ -1,23 +1,36 @@
--- ---
title: View a short summary of commits title: View a short summary of Git commits
type: snippet shortTitle: Short commits summary
type: story
language: git language: git
tags: [repository,commit] tags: [repository,commit]
author: chalarangelo
cover: dark-city cover: dark-city
dateModified: 2021-04-13T21:10:59+03:00 excerpt: Learn how to view a short summary of your Git commits using git log.
dateModified: 2023-05-23T21:10:59+03:00
--- ---
Prints a short summary of all commits. One of the most common things you might need to do when working with Git is to view a short summary of your commits. While `git log` is the go-to command for this, it can be a bit verbose at times. Luckily, it provides a plethora of options to help you customize its output.
- Use `git log --oneline` to list a short summary of all commits. ### Short summary of all commits
One of these is `--oneline`, which is actually a shorthand for `--pretty=oneline --abbrev-commit`. It prints a short summary of all commits, with each commit being printed on a single line.
```shell ```shell
git log --oneline git log --oneline
# d540ba1 Merge network bug fix
# 3050fc0 Fix network bug
# c191f90 Initial commit
``` ```
Notice the short, 7-character commit identifiers. This is because of the `--abbrev-commit` option, which abbreviates the commit SHA-1 checksum to 7 characters. This shorter string is enough to uniquely identify a commit.
### Short summary of commits without merges
Other options can be used in conjunction with `--oneline` to further customize the output. For example, you can use `--no-merges` to exclude merge commits from the output.
```shell ```shell
git log --oneline git log --oneline --no-merges
# d540ba1ab Merge network bug fix # 3050fc0 Fix network bug
# 3050fc0de Fix network bug # c191f90 Initial commit
# c191f90c7 Initial commit
``` ```

View File

@ -1,5 +1,6 @@
--- ---
title: View "undo" history title: View Git "undo" history
shortTitle: Undo history
type: story type: story
language: git language: git
tags: [repository,branch] tags: [repository,branch]
@ -15,7 +16,6 @@ To view you "undo" history, you can use `git reflog`, which displays the git ref
```shell ```shell
git reflog git reflog
# b6a4f9d6ff9 (HEAD -> patch-1, origin/patch-1) HEAD@{0}: Update docs # b6a4f9d6ff9 (HEAD -> patch-1, origin/patch-1) HEAD@{0}: Update docs
# 3050fc0de HEAD@{1}: rebase -i (finish): returning to refs/heads/patch-1 # 3050fc0de HEAD@{1}: rebase -i (finish): returning to refs/heads/patch-1
# 3050fc0de HEAD@{2}: rebase -i (pick): Fix network bug # 3050fc0de HEAD@{2}: rebase -i (pick): Fix network bug