I have a list of changed files in git repository. There is one file I don't wanna commit for the current moment. Can I do:
git commit -a
To commit all files and then somehow remove that file from current commit? After such removing it should still be in the list of uncommited files.
Commit the file means that it should be tracked in source control. If someone clones (or has a clone of) the repo, and the checkout a given version of your code, they should get the version of somefile.
Use Git reflog to check commits history. Git stash lets you discard changes and save them for later reuse. Try Git checkout --<file> to discard uncommitted changes to a file. Git reset --hard is for when you want to discard all uncommitted changes.
You want to do this:
git add -u git reset HEAD path/to/file git commit
Be sure and do this from the top level of the repo; add -u
adds changes in the current directory (recursively).
The key line tells git to reset the version of the given path in the index (the staging area for the commit) to the version from HEAD (the currently checked-out commit).
And advance warning of a gotcha for others reading this: add -u
stages all modifications, but doesn't add untracked files. This is the same as what commit -a
does. If you want to add untracked files too, use add .
to recursively add everything.
git rm --cached
will remove it from the commit set ("un-adding" it); that sounds like what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With