Then enter the full hash followed by a ^ symbol. Open a web browser and enter the following URL:Īdding your username and repository name will point the URL to your repo. Run a Git rev-list and find the commit hash. You just need to know which commit contains the deleted file. Simply look through your commit history by date, and then download any files from your project at any point in time. If you’ve committed your changes after deleting a file and pushed the changes to GitHub, you can attempt a recovery using the web UI. Right-click on the commit that contains the file you want to recover and choose revert changes in commit from the menu.Ī new commit will be created, and the previous one will be restored-along with the deleted file. Once located, go to your History tab in the desktop application. But the hashes won’t be displayed until you run a Git show command with the hash. You should see all of the listed commits along with their names. Instead, you’ll need to run Git rev-list from the command line. This can’t be done from the desktop application alone. If the file was deleted and you committed the changes, you need to find the commit hash. Once you confirm the changes in the pop-up window, the file will be recovered and sent back to its original location. GitHub will ask you to confirm this request. Then right-click on the file you’ve deleted in the staging area, and select discard changes. Just navigate to the left side of your desktop application to locate the deletion. If you have not committed the changes, you can easily recover the deleted file from the staging area. So if you’re more comfortable using a graphical interface, the GitHub desktop app for Windows and macOS might be easier for you.Īgain, you likely find yourself in one of two scenarios here as you’re attempting to recover the deleted file-your changes have been staged, or the changes have been committed. Many developers find the command line to be complicated for deleted file recovery. Step #2: Use the GitHub Desktop Application Then you can restore the file from that commit by adding a ^ symbol at the end of that commit hash, which tells GitHub to fetch the prior commit. This will show you the last commit where the deleted file was still present in the repository. You’ll have to run a Git show command with the checksum here. Then limit those results to only a single commit as a way to show an output of the commit that contains the deleted file. You can use the command line to list all commits, which can be found in the head. Then you’ll need to check out that file from your previous commit. This could take a bit longer, as you’ll need to locate the checksum of the commit that ultimately deleted the file. If the files have been deleted, staged, and committed, then you’ll need to use a Git checkout command to restore the deletion using the command line. This sequence tells Git to restore the file from the HEAD and working tree. Try entering Git restore –staged –worktree. In this scenario, you’ll have to use the command line to run something else. That’s because the file no longer exists in that index. Unfortunately, running this command after the changes have been staged will display an error code. Just enter Git restore to recover it instantly. If you haven’t staged the deleted files yet, you can quickly use the command line to restore the files from the index. Then you’ll use a Git add command to stage those changes and commit those changes using a Git commit command. Step #1: Use the Git Command LineĮach time you modify a file, create a new file, edit a file, or delete an existing file in GitHub, your changes are unstaged. This guide will show you multiple ways to recover deleted files in GitHub, so you can get back to work quickly without causing other issues for your team. Regardless of the reason for this error, deleting important files can be concerning if they’re not restored promptly-especially if you’re working with a team that pulls frequent changes in the project. Accidentally deleting the wrong file in a GitHub project happens to every developer.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |