Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverting one file in GitKraken

Tags:

gitkraken

It is possible in GitKraken to revert changes of a single file to an earlier commit instead of reverting an entire commit?

like image 925
Feofilakt Avatar asked Apr 07 '17 10:04

Feofilakt


People also ask

How do I revert a specific commit?

To undo changes associated with a specific commit, developers should use the git revert command. To undo every change that has happened since a given commit occurred, use git reset.

How do you revert to a previous commit GitKraken?

To revert a commit with GitKraken, simply right-click on any commit from the central graph and select Revert commit from the context menu.

How do I discard changes in GitKraken?

To discard changes, select the //WIP node to summon the icon. This option will discard all changes or discard any multi-selected files.


2 Answers

Answer

A revert in the git-sense of it can only be performed on a commit. It introduces a new commit that exactly negates the reverted commits' changes. See here. GitKraken supports this: right click on a commit, Revert <branch> to this commit.

What you want to accomplish, however, can be done via git checkout. I do not think GitKraken supports this funtionality for a single file yet. You can, however, use the command line.

Reset single file via command line

git checkout <commit> <file>

Check out a previous version of a file. This turns the <file> that resides in the working directory into an exact copy of the one from <commit> and adds it to the staging area.

Documentation can be found here.

git checkout HEAD~1 <filename> will thus reset a single file to the commit before the current HEAD.

like image 198
kowsky Avatar answered Sep 18 '22 16:09

kowsky


You can accomplish this in the GitKraken UI, but it's a little roundabout:

  • Revert the most recent commit(s) back to where the file was deleted, but when GitKraken asks if you want to immediately commit the reversion, click no.
  • Unstage all changes
  • Stage only the add for the file you're trying to restore
  • Right click in Unstaged, and Discard all

This should leave you with only an add for the one file you wanted to restore. Commit that, and now you've got your one file back.

Note that this can work across numerous commits, not just one... but since it's going to have to roll back everything from all of those commits, and then discard all of the rollbacks (except one) it can be quite slow if involves massive changes. In situations like this, it is probably better to use the git CI as suggested in kowsky's answer.

like image 45
Mir Avatar answered Sep 19 '22 16:09

Mir