11/7/2023 0 Comments Git cheat sheet background![]() It works by resetting your current HEAD branch to an older revision (also called "rolling back" to that older revision): $ git reset -hard 2be18d9Īfter this command, your currently checked out branch will be at revision 2be18d9. It neither produces any new commits nor does it delete any old ones. This reverts commit 2b504bee4083a20e0ef1e037eea0bd913a4d56b6.Īnother tool to "undo" commits is the "git reset" command. Revert "Change headlines for about and imprint" Revert "Change headlines for about and imprint"Ģ files changed, 2 insertions(+), 2 deletions (-)Ĭommit 364d412a25ddce997ce76230598aaa7b9759f434 ![]() Simply provide the hash of the commit you want to revert: $ git revert 2b504be For example, if your original commit added a word in a certain place, the reverting commit will remove exactly this word, again. It does this by producing a new commit with changes that revert each of the changes in that unwanted commit. Instead, it reverts the effects of a certain commit, effectively undoing it. However, the command doesn't delete any commits. Using the "git revert" command is one possibility to undo a previous commit. when you notice that your changes were wrong, when you introduced a bug, or simply when the customer has decided he doesn't want this anymore. 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. (b) You should never "amend" a commit that has already been published / pushed to a remote repository! This is because "amend" effectively produces a completely new commit object in the background that replaces the old one. ![]() Older commits can't be modified with "amend". (a) It can only be used to fix the very last commit.However, you'll need to keep the following things in mind when using it: Using the "amend" option is a great little helper that you'll come to appreciate yourself very quickly.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |