I want to pull a branch(master branch) to curr开发者_JAVA技巧ent repository, and replace the file that is existing, not just merge the file, the command git pull
is not appropriate to my needs, how to do that?
If you want to replace single file you can use this.
git checkout -- filename
Click here for more details
Why do you think it isn't appropriate?
git pull
will update your branch to the same state of the remote repository, so if the file you have is at a newer version on the remote, it will be replaced.
EDIT
If after the pull, merges are done with your local changes, you can reset to the state of remote repository with the following:
git reset origin/head -- <file-path>
So you've made a local commit affecting this file, and wish to discard your commit and just take the remote state without merging, is that right?
Assuming no-one else has seen your local commit (ie, you didn't push
and nobody pull
ed from your repo), you can just wind your local HEAD back to before the commit, and then do the pull.
NB. if you're not sure, run git fetch
first, and then git status
will tell you whether pull would be a fast-forward or a merge operation. Fast-forward means your local change is out of the picture.
It could very well be true that the question-asker actually knows exactly what he's talking about and just needs the mechanical how-tos answered, not a philosophy discussion.
git checkout -- (double dash) then the file name, space between double dash and filename
git checkout -- [file name in repo including path]
example: git checkout -- views/userEditor.pug
Less philosophy, more actual assistance. Sheesh.
精彩评论