![]() ![]() When we delete a branch, we will not see these commits either using the LOG function or from the browser level, when we open our git repository on GitHub or Bitbucket. They are alone, unrelated to anything, and in fact invisible. They exist, but there is nothing to point to them. So in theory, this previous commit and changes from a given branch are still in our repository. an indicator, we don’t delete the commit it was pointing to. This is why branches in GIT run very fast and are very “light”.īut it also has consequences. Branch is just a pointer to the commit, and the only information it contains is the SHA code of the commit it points to. ![]() But what happens when we delete a branch? What is a branch at all? By itself it does not store any information, commits do record it. Once a given file existed in the local repository, so despite its removal, the file still exists, saved in some previous commit. The GIT RESTORE operation should not raise any doubts – git has a linear history. ![]() Let’s consider how it is possible to recover data in git at all, since we have deleted them. Git checkout -b BRANCH SHA, where BRANCH is the name of the deleted branch, and SHA is the commit hash that the branch pointed to. Having the appropriate SHA code, we use the git CHECKOUT command, and specifically build the following git checkout command: Fortunately, using GIT RESTORE allows us to recover files without changing the history.Īnyway, we can use the familiar REV-LIST operation to find the SHA of the entire commit that contains the file, or we can use the REFLOG tool, which I think is a better idea. In the second case, however, we need to be more careful and take care of the correct commit history before we push our code. So the first case is easier because we can manipulate local history and local commits (those that have not yet been synchronized with the external repository). restore a file removed from the external git repository.Īs we know from the aforementioned article, changing the git history is a dangerous action.However, we will focus today not on cleaning up the Staging Area, but on restoring already deleted files. Here you can read more about other ways to restore or remove files in git. When we run the GIT STATUS command, the GIT RESTORE operation will be the suggested method to undo changes and it actually replaces the RESET command. It allows to unstage changes from Staging Area or to discard local changes. However, it is becoming an increasingly popular option, despite the fact that the official documentation still says: The RESTORE function was added to git version 2.23 (August 2019), so it is a relatively new thing. Thus, we are going to discuss one of the ways that will allow us to recover deleted files, named the GIT RESTORE function. It is convenient not just because you can do many different operations with it, including such git commands as git revert, git push, git reset, git rebase, or many more, but it also can permit you to restore deleted files.įortunately, for us, Git really has the right tools to do so. Git as a version control system is very popular nowadays. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |