How To Remove A File From The git Staging Pre-Commit List
erics, May 31st, 2019
Quickref: How to Remove a file from the staging area
1 |
git rm --cached {fileName(s)} |
The Story Recently, I accidentally added some files to git’s pre-commit phase, i.e.:
1 2 3 4 5 6 7 8 9 10 11 12 |
shell> git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: good1.xml new file: good2.xml new file: bad1.xml new file: bad2.xml modified: good3.xml modified: bad3.xml |
For example, here is how to handle the above situation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
shell> git rm --cached bad1.xml bad2.xml bad3.xml shell> git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: good1.xml new file: good2.xml modified: good3.xml Untracked files: (use "git add <file>..." to include in what will be committed) bad1.xml bad2.xml bad3.xml |
To better understand, here are the phases/states/stages that git uses: Untracked – when a file is first created, git […]