32

I learn Git and Using VSCode and just learn the commit "amend" command and now trying it on origin (GitHub).

I can't find any way to do this. Do I need some external tool to do that I don't see any "push amend" from the Git menu in VSCode

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
Kid
  • 1,869
  • 3
  • 19
  • 48
  • Unclear what you are asking. "amend" is always a local operation. If you amend an already-pushed commit, you have to force-push the branch (look up problems that this can cause). – knittl Sep 14 '20 at 10:39
  • Thanks ok so amend is always against the local repo good to know – Kid Sep 14 '20 at 10:40
  • So I must make another Push with the tiny change I forgot – Kid Sep 14 '20 at 10:42
  • Yes, amending always works against the local repo and if you amend something, it creates a new commit (replacing the old one), so you have to push again – knittl Sep 14 '20 at 10:47
  • I just read [this](https://github.blog/2015-06-08-how-to-undo-almost-anything-with-git/) that a GitHub can be reverted. What you think about this article is it ok? – Kid Sep 14 '20 at 14:05
  • 1
    What does "a GitHub can be reverted" – that sentence does not parse. Please be as explicit and specific as possible, use the correct terms and avoid ambiguitees. Efficient communication helps you and others. For the sake of Git commands, "GitHub" is only a remote repository, just like any other remote repository. – knittl Sep 14 '20 at 17:56

2 Answers2

63

You can go to Commit -> choose Commit All(Amend) or Commit Staged(Amend). Take a look at the picture.

enter image description here

Mohammad Alavi
  • 912
  • 1
  • 6
  • 16
  • After amending an already pushed commit, you'll have to use **force push**. If the option is not available in the "Pull, Push" menu item - Enable "Git: Allow Force Push" in settings (`Ctrl` + `,` and search for "force push"). – Noam Manos Mar 24 '23 at 21:07
  • 1
    This seems to include all projects rather than a specific one. The source control interface in Code really needs some work. I thought I could get by without Gitkraken, but the UI just lacks so much in usability and functionality as well. – Maciej Krawczyk May 22 '23 at 16:27
16

You do not push amend to the remote repo. git commit --amend allows you to include all current staged changes to your last commit in the local repo, instead of creating a new commit.

Let say you committed all changes but forgot to include a file include_me.js. You may run git add include_me.js, then git commit --amend to amend your last commit.

As mentioned by knittl, if you amend an already-pushed commit, you have to force-push the branch. Beware, if anyone has pulled the branch before you force push, they will have to reset their local branch.

Adam Tang
  • 332
  • 2
  • 3