Here's something that regularly happens to me at work:
[user@macmini ~/code/project $] git add .
[user@macmini ~/code/project $] git commit -m "Fixed whatever bug"
[master 93a3c47] Fixed whatever bug
3 files changed, 290 insertions(+)
create mode 100644 .DS_Store
create mode 100755 some-code.js
create mode 100755 some-other-code.js
As you can see, I've accidentally committed the .DS_Store
file which macOS like creating after you open a folder in Finder.
In this case I usually clone the repo again, copy and paste my new code in, and commit again without the .DS_Store
. But I know it's not the clean way to do it.
So, how can I cleanly undo a commit? I've tried git reset --hard HEAD
but it deletes my new files too.