Reverting one file in GitKraken
GitKraken 7.3.0 (probably older versions too) does allow for effectively running git checkout on a single file in the UI: Right click on the file under "unstaged files" and select "discard changes". Works on folders as well.
(This answer was previously a comment to the accepted answer)
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.
Although it doesn't strictly involves using git
commands, GitKraken offers the possibility to visualize the content of any project file at any given commit
.
When acting on a single file, it might be much easier to copy/paste the targeted commit file's content than using complicated git
commands that might very well end up messing your whole project's commit history.
To achieve this, simply:
- Open your git project in GitKraken
- Click on the desired commit in the commit history line
- In the right panel, check the View all files checkbox
- Locate the desired project file and click on it
- The file content will be displayed in the main panel
- You can now copy/paste the content
Simple and efficient when you only need to revert a very limited number of files...
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
.