I use git clone from github and I deleted some files & modified some files. Now I want to keep my local code & restore to the original form. Is there a command to achieve this?
Checkout old commitsSince this has the potential to overwrite local changes, Git forces you to commit or stash any changes in the working directory that will be lost during the checkout operation. Unlike git reset , git checkout doesn't move any branches around.
There are two Git commands a developer must use in order to discard all local changes in Git, remove all uncommited changes and revert their Git working tree back to the state it was in when the last commit took place. The commands to discard all local changes in Git are: git reset –hard. git clean -fxd.
The “Your local changes to the following files would be overwritten by merge” error occurs when you try to pull a remote repository to your local machine whose contents conflict with the contents of your local version of the repository. To fix this error, either stash your changes away for later or commit your changes.
Git command to pull all changes from branch by overwriting all local changes:-
git reset --hard HEAD
git pull
If you want to save you changes first, you can commit them before and then checkout you code to previous commit(s):
git checkout HEAD^
(one commit back)
git checkout GEAD~2
(2 commits back)
Or, if you don't need your changes anymore, run git reset --hard HEAD
git checkout <name of file>
If you want to check out the whole repository, then from the root directory use
git checkout .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With