Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pull and replace the file that is existing

Tags:

git

I want to pull a branch(master branch) to current 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?

like image 385
coolesting Avatar asked Sep 05 '11 11:09

coolesting


People also ask

How do I pull a specific file in git?

git checkout origin/master -- path/to/file // git checkout / -- path/to/file will checkout the particular file from the downloaded changes (origin/master). That's it!


1 Answers

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 pulled 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.

like image 165
Useless Avatar answered Oct 21 '22 07:10

Useless