![]() Second, git revert is able to target an individual commit at an arbitrary point in the history, whereas git reset can only work backwards from the current commit. For details about why altering shared history is dangerous, please see the git reset page. First, it doesn’t change the project history, which makes it a “safe” operation for commits that have already been published to a shared repository. Reverting has two important advantages over resetting. In Git, this is actually called a reset, not a revert. It’s important to understand that git revert undoes a single commit-it does not “revert” back to the previous state of a project by removing all subsequent commits. Instead of manually going in, fixing it, and committing a new snapshot, you can use git revert to automatically do all of this for you. This can be useful, for example, if you’re tracking down a bug and find that it was introduced by a single commit. Reverting should be used when you want to remove an entire commit from your project history. Generate a new commit that undoes all of the changes introduced in, then apply it to the current branch. ![]() This prevents Git from losing history, which is important for the integrity of your revision history and for reliable collaboration. But, instead of removing the commit from the project history, it figures out how to undo the changes introduced by the commit and appends a new commit with the resulting content. The git revert command undoes a committed snapshot. In the following part, some methods of rollback to a previous state will be elucidated. This concludes the part on checking your previous commits. If you decide you don’t want to keep the old version, you can check out the most recent version with the following: git checkout HEAD hello.py The old file revision will show up as a “Change to be committed,” giving you the opportunity to revert back to the previous version of the file. Remember, unlike checking out a commit, this does affect the current state of your project. For example, if you only wanted to see the hello.py file from the old commit, you could use the following command: git checkout a1e8fb5 hello.py If you’re only interested in a single file, you can also use git checkout to fetch an old version of it. To continue developing, you need to get back to the “current” state of your project (assuming your master branch is the head of the project): git checkout master It’s impossible to harm your repository while viewing an old revision. Checking out an old commit is a read-only operation. Nothing you do in here will be saved in your repository. ![]() You can look at files, and even edit files without worrying about losing the current state of the project. This makes your working directory match the exact state of the a1e8fb5 commit. You can use git checkout to view the “Make some import changes to hello.py” commit as follows: git checkout a1e8fb5 ![]() (This will put you in a detached HEAD state.) Checking out a file lets you see an old version of that particular file, leaving the rest of your working directory untouched. This can be used to view an old state of your project without altering your current state in any way. Checking out a commit makes the entire working directory match that commit. In this part, only the first two configurations are addressed. The git checkout command serves three distinct functions: checking out files, checking out commits, and checking out branches. git log -onelineĮxample output b7119f2 Continue doing crazy thingsĪ1e8fb5 Make some important changes to hello.py ![]() No worries, erroneous commits can be undone or reverted.įirst, check your history of commits to see which commits are the faulty ones. You notice you have done something wrong on your branch. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |