1

There was a commit made by another developer that changed several files including one that I had been working on.

commit 518cf1750987d789786c7f2f095e4c892fc9bc1f

File: J/Views/CardsTab/CardsTab.xaml

Looking at the History in Github, it seems to have overwritten many changes that I was doing.

Is there a way that I can restore just that one file to the state it was before the commit?

Alan2
  • 23,493
  • 79
  • 256
  • 450
  • 1
    See https://stackoverflow.com/questions/215718/reset-or-revert-a-specific-file-to-a-specific-revision-using-git – VonC Apr 08 '19 at 04:46

2 Answers2

0

You can try soft resetting the commit in which the files that you want have changes using the command : git reset --soft commitid . After that you can use the following command to reset that single file to the HEAD as you see fit.

You can use the following command to reset the changes for a particular file to index:

 git checkout -- CONTRIBUTING.md

The following command will reset the file to HEAD ,this will update both the working copy and the index to HEAD:

git checkout HEAD -- CONTRIBUTING.md

Reference: https://git-scm.com/docs/git-checkout

Or another method i think that will work is :

  1. Soft reset the commit that have the changes on files you want to edit
  2. Commit again with the files that you don't want to edit leaving out just your J/Views/CardsTab/CardsTab.xaml
  3. Reset the branch to the last commit

This should leave your working branch clean with only your desired changes.

Ananthapadmanabhan
  • 5,706
  • 6
  • 22
  • 39
0

You can use git checkout to reset a file in the working directory to the state it was in a particular commit.

If I understand it right, the "bad" commit was 518cf1750987d789786c7f2f095e4c892fc9bc1f and you need to reset your file to be as it was before that. So the command line you're looking for is this one:

git checkout 518cf1750987d789786c7f2f095e4c892fc9bc1f^ -- J/Views/CardsTab/CardsTab.xaml

which means "retrieve me the file J/Views/CardsTab/CardsTab.xaml as it was in the commit before 518cf1750987d789786c7f2f095e4c892fc9bc1f (^ is a reference to the parent of the commit).

GL!

Andrey Tserkus
  • 3,644
  • 17
  • 24