Restore original file which was deleted during patch creation
I have just started using git. For some reason I have to create a patch of my changes which inclueds (file modification + 4 new files creation). I am successfully able to cretae a patch. But during this process some how those files which I have created got deleted. I want those files again. How can I get that.
- Git: Is it possible to add files located in an external directory to a git repository?
- Using git wagon plugin to store jars at github/gitlab
- Git change history of feature-branch into a new branch?
- Adding SSH Keys to remote servers
- Commits can't close issues on github remote repository
- svn to git migration keeping history of copied file
2 Solutions collect form web for “Restore original file which was deleted during patch creation”
If those files were committed, a simple
git checkout - # or git checkout -f HEAD
should be enough to checkout again the content of the working directory (but it can override any current – not-yet-committed – work), so be careful (a
git stash could be useful first).
Do you need to use patches? Assuming where you are sending them, they are using git as well, you can just send them a git bundle. Take a look at the
git bundle command here: http://www.kernel.org/pub/software/scm/git/docs/git-bundle.html
If you generated the patches for the new files by taking the output of
git diff, you won’t be able to issue any git commands to get them back as they were never part of anything that git tracked. Simply recreate the files by cutting out the contents of the patches you made.
If you generated the patches for the new files after having committed them to history you can get back to the original state of that latest commit by any one of these methods:
git stash git checkout -- . git reset --hard
be careful that you don’t have existing work when doing this. Stash is the safest one of all those commands as it stores the state of your modifications in a reference in history. In case you zapped something, you can get it back with