-
Notifications
You must be signed in to change notification settings - Fork 0
Git
| Prefix | Purpose | Typical Usage |
|---|---|---|
| feat | A new feature or capability | Adding a new function, endpoint, component, etc. |
| fix | A bug fix | Resolving a defect, regression, or incorrect behaviour. |
| docs | Documentation only changes | Updating README, code comments, API docs, etc. |
| style | Code style or formatting | Changing whitespace, indentation, naming, etc. (no logic changes). |
| refactor | Code change that neither fixes a bug nor adds a feature | Improving structure, readability, or design without altering behaviour. |
| perf | A change that improves performance | Optimisations such as caching, reducing complexity, etc. |
| test | Adding or correcting tests | Unit, integration, or snapshot tests. |
| build | Changes that affect the build system or external dependencies | Adjusting npm scripts, build pipelines, dependencies, or tooling. |
| ci | Continuous Integration / deployment related changes | GitHub Actions, Jenkins, CircleCI, etc. |
| chore | Routine tasks or maintenance | Version bumps, dependency updates, configuration tweaks, etc. |
| revert | Reverting a previous commit | Undoing a change with the commit hash. |
If the commit only exists in your local repository and has not been pushed to your online repository, then you can amend the commit message with the git commit --amend command.
-
On the command line, navigate to the repository that contains the commit you want to amend.
-
Enter the following:
git commit --amend -
In your text editor, edit the commit message, and save the commit.
You can add a co-author by adding a trailer to the commit. For more information, see "Creating a commit with multiple authors."
You can create commits on behalf of your organization by adding a trailer to the commit. For more information, see "Creating a commit on behalf of an organization"
The new commit and message will appear in your repository host the next time you push.
If you have already pushed the commit, you will have to force push a commit with an amended message.
We strongly discourage force pushing, since this changes the history of your repository. If you force push, people who have already cloned your repository will have to manually fix their local history.
-
Follow the steps above to amend the commit message.
-
Use the push --force-with-lease command to force push over the old commit.
$ git push --force-with-lease origin example-branch
If you need to amend the message for multiple commits or an older commit, you can use interactive rebase, then force push to change the commit history.
-
On the command line, navigate to the repository that contains the commit you want to amend.
-
Use the
git rebase -i HEAD~ncommand to display a list of the last n commits in your default text editor.
# Displays a list of the last 3 commits on the current branch
$ git rebase -i HEAD~3
The list will look similar to the following:
pick e499d89 Delete CNAME
pick 0c39034 Better README
pick f7fde4a Change the commit message but push the same commit.
# Rebase 9fdb3bd..f7fde4a onto 9fdb3bd
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
- Replace
pickwithrewordbefore each commit message you want to change.
pick e499d89 Delete CNAME
reword 0c39034 Better README
reword f7fde4a Change the commit message but push the same commit.
- Save and close the commit list file.
In each resulting commit file, type the new commit message, save the file, and close it.
When you're ready to push your changes to GitHub, use the push --force command to force push over the old commit.
$ git push --force origin example-branch
git branch localBranchName
git push --set-upstream origin localBranchName
git push -u origin localBranchName
git branch -d branchName
git branch | grep -v "develop" | xargs git branch -d
git branch -D branchName
git push origin --delete remoteBranchName
git branch -d -r origin/mybranch
git remote prune origin
- Ensure that you are in the branch that you want to merge the changes into.
git branch
Note: Use the following to switch to the correct branch if you are not
git checkout {branch_name}
- Merge the changes `git merge {branch_name_to_merge_into_current_branch}
Git will then try to automatically merge the changes from the specified branch into the current branch. If there are any conflicts between the changes, Git will notify you and prompt you to resolve them manually.
- Once you have resolved any conflicts, add and commit the changes using
git add
git commit
- Push the changes to the remote repository
git push
Note: It is always recommended to create a backup branch or clone of the repository before performing a merge in case anything goes wrong.