DEV Community

loading...

Reset git add after commit or push

Heddi Nabbisen
An ICT designer/developer and a security monk with "a cool brain and a warm heart". OpenBSD/Rust etc. Interested in social issues and relationships. Founder of Scqr Inc.
・1 min read

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.

Discussion (0)