User Tools

Site Tools


git:correcting-git-commits

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
git:correcting-git-commits [2025/07/27 18:39] โ€“ created odeftagit:correcting-git-commits [2026/02/11 15:40] (current) โ€“ [How to Do It (Command Line)] odefta
Line 19: Line 19:
  
 ==== How to Do It (Command Line) ==== ==== How to Do It (Command Line) ====
- 
   - **Step 1: Amend the Commit Locally**   - **Step 1: Amend the Commit Locally**
     Run the following command. This will open your default text editor to let you change the message.     Run the following command. This will open your default text editor to let you change the message.
Line 29: Line 28:
 git commit --amend -m "feat(auth): [JIRA-123] Add user login endpoint" git commit --amend -m "feat(auth): [JIRA-123] Add user login endpoint"
 </code> </code>
- 
   - **Step 2: Push the Changes to the Server**   - **Step 2: Push the Changes to the Server**
     Because you have changed a commit that already exists on the remote server, you must force the update. **Always** use the safer `--force-with-lease` option.     Because you have changed a commit that already exists on the remote server, you must force the update. **Always** use the safer `--force-with-lease` option.
 <code bash> <code bash>
 +# Short version (when the branch already has upstream configured)
 +git push --force-with-lease
 +
 +# Full version (explicitly specify remote and branch)
 git push --force-with-lease origin <your-branch-name> git push --force-with-lease origin <your-branch-name>
 </code> </code>
 +<note tip>
 +๐Ÿ’ก **Tip:** In most cases you can use the short version. Git will automatically use the configured upstream for the current branch.
 +</note>
 <note> <note>
 The <code>--force-with-lease</code> flag is safer than <code>--force</code> because it checks if another person has pushed new commits to the branch in the meantime. If they have, the push will fail, preventing you from accidentally overwriting their work. The <code>--force-with-lease</code> flag is safer than <code>--force</code> because it checks if another person has pushed new commits to the branch in the meantime. If they have, the push will fail, preventing you from accidentally overwriting their work.
 </note> </note>
- 
 --- ---
- 
 ===== 2. Combining Multiple Commits (Squash) ===== ===== 2. Combining Multiple Commits (Squash) =====
  
git/correcting-git-commits.1753641569.txt.gz ยท Last modified: by odefta