0

ALL,

I'm trying to resolve a following situation.

I am developing a program whose code is on Git. At one point of time I needed to update the code on Mac. The pull failed because there was an un-committed changes. One of the file which was un-committed was the Xcode file.

I tried to commit the file and pull again, but unfortunately I got a conflict. I tried to resolve the conflict with the vi and editing by hand, but I guess the Xcode internal files are not meant to be edited by hand.

Now I can go back and checkout the last known commit which will obviously won't have a latest source.

So after I do:

git checkout <last_known_commit>

what do I do in order to just bring the soure code in?

Or maybe I can reset the file from the master?

Please help.

Thank you.

Igor
  • 5,620
  • 11
  • 51
  • 103
  • Please read [Hard reset of a single file](https://stackoverflow.com/questions/7147270/hard-reset-of-a-single-file). – Tim Biegeleisen Apr 10 '19 at 05:31
  • @TimBiegeleisen, this is not the answer I'm looking for. As I said the file in question was already committed and pushed to remote along with other {source} files. The link you referenced talks about non-committed file. Thank you, though. – Igor Apr 10 '19 at 17:50
  • I disagree, and the link I gave in fact does explain how to checkout a version of a single file from some other commit. – Tim Biegeleisen Apr 10 '19 at 23:44

2 Answers2

1

I cannot comment yet, so here my thoughts: As usually in git, you have many options to resolve an issue. The quick fix would be reset/revert your file and push that. Since you pushed your code already, that will be visible in the repo for others, but it will work. A more elegant, yet more complex, solution was presented by @argo.

A note for your Xcode IDE file: It can make sense to insert those files into the respective git ignore if those files are induvial for each developer. I recall adding some Xcode files in the past, but I cannot remember which. I am sure you will find recommendations online.

tomwaitforitmy
  • 509
  • 3
  • 16
  • I just did what your linked page suggested and it worked. Thank you. Also, as a side note I did add some Xcode files to gitignore, but this file according to the Google search shuoldn't be there. – Igor Apr 11 '19 at 15:01
0

You can follow the these steps:

  • Checkout to the version where you did last local commit.

    git checkout <commit id>

  • Then create a branch from there

    git checkout -b my-branch

  • make a git remote push of that branch. Do make sure the branch is present with all your local changes in the remote server

  • now do git reset hard

    git reset --hard origin/master

Tada you are having the remote master updated. Now perform a merge to update your local changes to the master

git checkout master
git merge my-branch
Arghya Saha
  • 5,599
  • 4
  • 26
  • 48
  • I'm not sure I follow the process. Can elaborate? All I need is to reset one file - Xcode project. The source code should be kept locally and remotely. And I don't see the changes to the file... – Igor Apr 10 '19 at 12:54