简体   繁体   中英

Override local files with Git Pull | Discard all local files and directories and git the complete latest code from the repo

I want get complete latest code from the git server and need to override my local machine changes. Meaning I want to remove all my local untrack files and directories and than get the latest code from the remote repository. Is it possible to do with git?

As per your question, I have understood, you have to remove all you untrack files (files which you have changed in your local machine) and get latest code from the remote repository and keep your git tree clean. if my understanding is correct, please find the solution for this question below:

Please note when you do this, you will loose all your uncommitted local changes.

Step 1 To remove the untrack files

git checkout .
git clean -f

Step 2 To remove the untrack directories

git clean -f -d

Step 3 To get latest codes

git fetch --all
git reset --hard <remote>/<branch_name>

For example

git checkout .
git clean -f
git clean -f -d
git fetch --all
git reset --hard origin/master

Try this:

git reset --hard HEAD
git pull

You'll lose anything that's not in the repo though

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM