Igor
Igor

Reputation: 6245

Reset one file from many already pushed in git

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.

Upvotes: 0

Views: 154

Answers (2)

tomwaitforitmy
tomwaitforitmy

Reputation: 717

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.

Upvotes: 1

Arghya Saha
Arghya Saha

Reputation: 5713

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

Upvotes: 0

Related Questions