git-guide/commit.md
2024-05-02 13:23:23 +01:00

27 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## Working with commits
When working with commits, utilize git commit -m to record changes, git amend to modify the most recent commit, and try your best to adhere to commit message conventions.
```
# Make sure to add a message to each commit
git commit -m "meaningful message"
```
If you have changes to your last commit, you dont have to create another commit altogether, you can use the - — amend flag to amend the most recent commit with your staged changes
```
# make your changes
git add .
git commit --amend
# This will open your default text editor to modify the commit message if needed.
git push origin your_branch --force
```
> Exercise caution when utilizing --force, as it has the potential to overwrite the history of the target branch. Its application on the main/master branch should be generally avoided.
As a rule of thumb its better to commit more often than not, to avoid losing progress or accidentally resetting the unstaged changes. One can rewrite the history afterwards by squashing multiple commits or doing an interactive rebase.
Use git log to show a chronological list of commits, starting from the most recent commit and working backward in time
### Sync Commits