How To Remove A File From The git Staging Pre-Commit List
erics, Posted May 31st, 2019 at 4:07:10pm
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 sees it and knows it has not yet been told to handle this file
- Staged/Indexed – git add will signal git to start tracking the file, and so git places the file into the staging state, ready to commit
- Committed – the git commit command can be called upon a single file or use -a to commit all staged files
- Modified- a file has already been committed at least once before, and now new changes exist in the local file(s) which are not committed or staged yet.
Leave Your Comment
All fields marked with "*" are required.