Do not want to switch the entire repository to an older commit and back?...
A combination of git aliases/awk/shell-functions to the rescueHere is a quick and intuitive way to checkout a older version of a single file in git.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Start by adding the following alias to your gitconfig. | |
[alias] | |
prevision = "!f() { git checkout `git log --oneline $2 | awk -v commit="$1" 'FNR == -commit+1 {print $1}'` $2;} ;f" | |
Usage: | |
$ git prevision <N> <filename> | |
will checkout the <N>th revision (counting backwards from HEAD) into the history of the file <filename>. | |
For example to checkout the immediate previous version of a file x/y/z.c use | |
$ git prevision -1 x/y/z.c | |
Have fun! |
Essentially, all that one would manually do in this situation, wrapped-up in one beautiful, efficient git-alias - git-prevision
Liked git-prevision? Help others discover git-prevision.
Upvote git-prevision on StackOverflow.
No comments :
Post a Comment