Addresses issue #63622 (#63624)

Co-authored-by: mstuffer <mstuffer@soundhound.com>
This commit is contained in:
Michael Stuffer 2023-05-14 00:39:13 +02:00 committed by GitHub
parent f47450519b
commit 9e257dc83d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -3,7 +3,7 @@
We assume that you have already finished with the basic tutorial before coming here. This document will give you some additional information about advanced Git techniques.
### [Amending a commit](amending-a-commit.md)
This document provides information about how to amend a commit on the remote repository.Amending a commit is a way to modify the most recent commit you have made in your current branch. This can be helpful if you need to edit the commit message or if you forgot to include changes in the commit. You can continue to amend a commit until you push it to the remote repository.
This document provides information about how to amend a commit on the remote repository. Amending a commit is a way to modify the most recent commit you have made in your current branch. This can be helpful if you need to edit the commit message or if you forgot to include changes in the commit. You can continue to amend a commit until you push it to the remote repository.
> Use this when you need to adjust a commit you made.
### [Configuring git](configuring-git.md)

View File

@ -46,3 +46,20 @@ But since what we want to achieve here is to amend the previous commit, we would
* Push your changes with ```git push origin <branch-name>```
That way, both changes would be in one single commit.
## Modifying commits on remote
If the commit that you like to amend has been already pushed to the remote, amending this commit will lead to your local history being diverged from the remote (since you basically create a new commit and replace the amended one). Since you want to change the commit on the remote, you need to overwrite the remotes history on your branch. To achieve that, follow the same procedure as described above, but use force push when pushing your commit to the remote.
> **Warning**
> Force pushing to the remote will overwrite (and discard) changes on the remote and only keep your pushed commits. Changes on the remote, that other team members did in the meantime, will be overwritten as well.
This is how you modify the last recent commit on the remote:
```bash
git add <your changed files>
git commit --amend -m "followed by your new commit message"
git push --force
```
> Using `--force-with-lease` is a safer option instead of `--force` which avoids overwriting other people's changes on the remote branch (if you do not intend to do so).