-1

This problem is already asked in this website. But still, I could not find the correct solution. one solution given, is to use-

git reset --hard origin/master

But I am not very sure how to use this if I have to do it for my single file. This seems a very basic question to me, but I am having a lot of issues. I made few changes to a file parent.java in local because that file was extended in my file child.java. But tomorrow, someone changes parent.java, and now I have to use latest parent.java in child.java, so I find it hard to overwrite parent.java file with the latest repository file.

anubhs
  • 566
  • 1
  • 8
  • 26
  • `git reset --hard origin/master` replaces everything you have in the working tree with the files from the `origin/master` branch. It is not what you need. You need `git checkout origin/master -- file`; replace `file` with the path to the file you want to overwrite. – axiac Apr 21 '17 at 11:30

2 Answers2

0

In this case you have to manually merge your changes, the best way is when you take pull, crate your own branch and work, later on commit your changes on staging and move to the branch from where you created and take pull and merge your branch then push remotely., you also also push your branch remotely then can do same operation above..

kj007
  • 6,073
  • 4
  • 29
  • 47
0

Another answer is mentioning merging master into your branch, they are correct.

Example:

git checkout master
git fetch
git reset --hard origin/master
git checkout <yourbranch>
git merge master

At this point you may have conflicts that you will have to resolve, if not then you will have the following:

  1. parent.java will be updated to the version in master
  2. child.java will still have your changes within it
Stefan Theard
  • 351
  • 3
  • 9