Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: How to overwrite local change?

Tags:

git

restore

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?

like image 939
mlzboy Avatar asked Nov 01 '10 11:11

mlzboy


People also ask

Does git checkout overwrite local changes?

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.

How do I remove local changes from a git branch?

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.

How do you fix error your local changes to the following files would be overwritten by merge?

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.


3 Answers

Git command to pull all changes from branch by overwriting all local changes:-

git reset --hard HEAD
git pull
like image 148
Mradula Ghatiya Avatar answered Oct 12 '22 22:10

Mradula Ghatiya


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

like image 12
seriyPS Avatar answered Oct 20 '22 11:10

seriyPS


git checkout <name of file>

If you want to check out the whole repository, then from the root directory use

git checkout .

like image 8
Nick Moore Avatar answered Oct 20 '22 12:10

Nick Moore