Force overwrite of local file with what's in origin repo?
I want to get the latest file that's in the repository, and overwrite what I have locally. How can I do thi开发者_C百科s with the git client?
If you want to overwrite only one file:
git fetch
git checkout origin/master <filepath>
If you want to overwrite all changed files:
git fetch
git reset --hard origin/master
(This assumes that you're working on master
locally and you want the changes on the origin's master
- if you're on a branch, substitute that in instead.)
Simplest version, assuming you're working on the same branch that the file you want is on:
git checkout path/to/file
.
I do this so often that I've got an alias set to gc='git checkout'
.
This worked for me:
git reset HEAD <filename>
I believe what you are looking for is "git restore".
The easiest way is to remove the file locally, and then execute the git restore command for that file:
$ rm file.txt
$ git restore file.txt
Full sync has few tasks:
- reverting changes
- removing new files
- get latest from remote repository
git reset HEAD --hard
git clean -f
git pull origin master
Or else, what I prefer is that, I may create a new branch with the latest from the remote using:
git checkout origin/master -b <new branch name>
origin is my remote repository reference, and master is my considered branch name. These may different from yours.
if you want to override all your local changes with specific branch then u can do
git reset --hard origin/feature/branchname
feature/branchname -> is my branch name by which I replaced my all local changes
My intention to take all the changes from feature/branchname branch and commit to a branch in which I am working, the name of my branch is 'mybranch'. Then I first replaced my local changes which is I already pushed to my branch mybranch, then I have to pushed this command to my branch. Force push command is
git push --force
It will push whatever changes I got from 'feature/branchname' branch to my 'mybranch'.
After running into this problem, I finally tried git checkout --force <branch>
and it did exactly that.
精彩评论