Several scripts that I have found useful while developing software with git.
Mostly packages for fetching specific versions of files and comparing them
using Emacs.
Compare a file against some version from its git history, or compare two
historic versions of a file. The two versions are loaded into GNU Emacs and an
ediff-buffers command is executed against the pair.
If multiple files are specified, then the first file/revisions are be compared in Emacs. After Emacs terminates, the next will be compared, etc.
Usage: gitediff <file>[[#<rev>]#<rev>] [<file>[[#<rev>]#<rev>] ...]
Where:
-
<file>is a filename. An absolute or relative path to a file that is undergitversion control -
[[#<rev>]#<rev>]is an optional 1- or 2-term version expression:-
If omitted, the local version of the file is compared against the current version on the branch or the version staged for commit (e.g. after a
git addoperation). -
If only one term (
#<rev>) is provided, the local version of the file is compared against the specified version provided. -
If two terms (
#<rev>#<rev>) are provided, then the two specified versions are compared against each other. -
Within the version expression:
-
The
#character is a literal. It delimits between filenames and revisions. -
<rev>represents a revision of the file:-
It can be any
gitrevision specifier (commit number, tag, branch name, HEAD expression, etc.) -
A negative integer (e.g.
-1or-5) represents a version along the file's commit history.-1represents the most recently committed version.-2represents the version prior to that, etc.Note that this is different from Git expressions like
HEAD~3orHEAD^3, which specify a number of prior/parent commits, whether or not the specified file changed in every one of those commits. This script's-3expression only counts those where the specified file changed.
-
-
-
Some examples may help:
-
gitediff foo.cCompare
foo.cagainst the most-recent versiongitknows about (current version on the branch or version staged for commit). Great for checking what you're currently working on. -
gitediff foo.c#HEADCompare
foo.cagainst theHEADrevision. This should be the current commit on the branch, whether or not there is another version staged for commit. -
gitediff foo.c#-5Compare
foo.cagainst its 5th-generation prior commit (according to the file'sgit loghistory. -
gitediff foo.c#origin/masterCompare
foo.cagainst the version at the head oforigin/master. Expressions like this are useful for comparing your local head-of-branch against a remote head-of-branch, to see the changes prior to agit pushoperation. -
gitediff foo.c#release5branchCompare
foo.cagainst the version at the head ofrelease5branch -
gitediff foo.c#release4branch#release5branchCompare the version of
foo.cat the head ofrelease4branchagainst the version at the head ofrelease5branch
Compare two arbitrary files, allowing git revisions to be specified for each.
The two files are loaded into GNU Emacs and an ediff-buffers command is
executed against the pair.
If more than two files are specified, then the first two are compared in Emacs. After Emacs terminates, the next two will be compared, etc.
Usage: gitediff2 <file>[#<rev>] <file>[#<rev>] [<file>[#<rev>] <file>[#<rev>] ...]
Where:
-
<file>is a filename. An absolute or relative path. If a revision is specified, then the file must be undergitversion control. -
[#<rev>]is an optional version expression:-
If omitted, the local version of the file is used.
-
If provided, the specified version is retrieved from
gitfor the comparison.See gitediff, above, for the
#<rev>syntax.
-
View all of the changes corresponding to a single git commit, either
comparing each file against its immediately-prior version or against specified
earlier versions. For each file in the specified commit, the two appropriate
versions are loaded into GNU Emacs and an ediff-buffers command is executed
against them. After Emacs terminates, the next file is compared.
Usage: gitediffcommit <commit_no> [<base>]
Where:
-
<commit_no>is agitcommit number -
<base>is an optional version expression representing the base version against which each file belonging to the commit is compared.-
If omitted, each file in the commit is compared against its immediately prior version. That is, the file's diff for the commit itself.
-
If provided, the specified version that the file's version (at the time of the commit) is compared against. The syntax is the
#<rev>syntax, used by gitediff, above.
-
Some examples may help:
-
gitediffcommit 1234abcdShow all of the diffs belonging to commit number
1234abcdand compare it against its immediately prior version. This is effectively the same as viewing the diffs with agit showcommand, but using Emacs'ediff-buffersto browse the differences. -
gitediffcommit 1234abcd foobieShow all of the files belonging to commit number
1234abcdand compare it against its content for the commit namedfoobie. -
gitediffcommit 1234abcd HEADShow all of the files belonging to commit number
1234abcdand compare each against its current version for the checked-out branch. -
gitediffcommit 1234abcd -5Show all of the files belonging to commit number
1234abcdand compare each against its version 5 commits prior to the HEAD. IMPORTANT: This is relative to the branch's head, not to the commit being viewed.
View all of the changes between two git commits. For each file that differs,
load the two versions into GNU Emacs and use ediff-buffers to compare them.
After Emacs terminates, the next file is compared.
Usage: gitediffcommit2 <commit1> [<commit2>]
Where:
-
<commit1>is agitcommit number -
<commit2>is an optional secondgitcommit number. If present, the differences between the two commits is compared. If not provided, then the specified commit is compared against the local version of each file.
It is extremely useful in the following examples:
-
gitediffcommit2 HEADShow all of the differences between the current working space and the most recent commit on its branch. When run prior to a
git commit, it will show all the changes that will be committed, allowing for a quick review prior to committing the changes. -
gitediffcommit2 otherbranchShow all the differences between the current working space and the head of the
otherbranchbranch. This is very useful when manually merging two branches, because you can review the diffs on a per-file basis and make changes to the current working space using theediff-buffersmechanism.
View an arbitrary files, allowing a git revision to be specified. The file
is loaded into GNU Emacs
If more than one files is specified, then the first is loaded into Emacs. After Emacs terminates, the next is loaded, etc.
Usage: gitview <file>[#<rev>] [<file>[#<rev>] ...]
Where:
-
<file>is a filename. An absolute or relative path. If a revision is specified, then the file must be undergitversion control. -
[#<rev>]is an optional version expression:-
If omitted, the local version of the file is used.
-
If provided, the specified version is retrieved from
gitfor the comparison.See gitediff, above, for the
#<rev>syntax.
-
View the most recent log entry for a group of repositories, identified by the directories to which they have been cloned.
Usage: githead [<directory>...]
Where:
<directory>is a directory under Git version control.
For each directory specified, the script will perform a git log -1, showing
information about the most recent commit.