iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
📑

How to remove an accidentally committed new file from a commit

に公開
git rm --cached {file}
git commit --amend

Example

$ git log --name-status
A   content/blog/2020/2020-12-17___sort-without-head.md
A   content/blog/2020/2020-12-28___undo-commited-new-file.md

I mistakenly included 2020-12-28___undo-commited-new-file.md in the commit.

$ git rm --cached content/blog/2020/2020-12-28___undo-commited-new-file.md
$ git commit --amend
$ git log --name-status # Check
A   content/blog/2020/2020-12-17___sort-without-head.md
$ git status
Untracked files:
  (use "git add <file>..." to include in what will be committed)
	content/blog/2020/2020-12-28___undo-commited-new-file.md
GitHubで編集を提案

Discussion