I have a local git repository, but things get wrong and complicated and I simply want to overwrite all the files in my local directory with the latest version of what is on the remote repository. This would be like a clone, but for an already setup local git repository.
For example: if use git pull
, then I don't get locally deleted folders back from the remote.
Is it checkout
that I must use? But how to tell it to retrieve the files from a remote (and not from the stage) and overwrite all?
When you have pushed some commits to the remote repository and would like to undo those changes, you need to use the revert command to create a new commit, undoing all those changes. Note that history will not be rewritten in case of a revert.
To undo the last commit from a remote git repository, you can use the git reset command. command. This will undo the last commit locally. command to force push the local commit which was reverted to the remote git repository.
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.
You probably want to use git reset
. Assuming you have done a git fetch
recently, the following will discard everything in your local and reset it to the point you specify as the final argument (in this case the current HEAD of the origin/master
remote tracking branch):
$ git reset --hard origin/master
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