DEV Community

nabbisen
nabbisen

Posted on

Reset git add after commit or push

I also sometimes meet the situation:

$ git add .

$ git commit -m "<commit-comments>"
[main xxxxxxxx] <commit-comments>
 99 files changed, 99999 insertions(+)
 ...
 create mode 100644 <unexpected-file>
Enter fullscreen mode Exit fullscreen mode

"Hey, wait ( ゚д゚)"

In such a case, git reset HEAD^ <unexpected-file> is available.

$ git reset HEAD^ <unexpected-file>
[main xxxxxxxx] <commit-comments>
 98 files changed, 98888 insertions(+)
 ...
$ # "create ... <unexpected-file>" is not printed

$ git commit --amend
$ # HEAD^ is changed
Enter fullscreen mode Exit fullscreen mode

Happier, possibly🙂

Besides, when git push has been already done, running git push --force|-f origin main after the commit above updates the remote repository. It may affect others.

Top comments (0)