Sometimes you'll want to undo a certain commit. Therefore, Git has no chance to restore this kind of changes.Īlways keep this in mind when discarding local changes. This is because they have never been saved in your repository. This tells Git to replace the files in your working copy with the "HEAD" revision (which is the last committed version), discarding all local changes.ĭiscarding uncommitted changes cannot be undone. If you need to discard all current changes in your working copy and want to restore the last committed version of your complete project, the "git reset" command is your friend: $ git reset -hard HEAD However, if you use it with the HEAD reference and the path to a file, it will discard any uncommitted changes in that file. You already know that the "checkout" command is mainly used to switch branches. To restore a file to its last committed version, you use the "git checkout" command: $ git checkout HEAD file/to/restore.ext These are the times when you want to discard these changes and start fresh with the last committed version. Replacing it with an amended version will cause problems.Ĭhanges are called "local" when they haven't been committed, yet: all the modifications that are currently present in your working directory are "local", uncommitted changes. However, after publishing the original commit on a remote, other people might already have based new work on this commit. If you're the only person who had this commit, doing this is safe.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |