Skip to content

Helpful Git Commands

Michael O'Cleirigh edited this page Jan 11, 2011 · 8 revisions

Get back the previous version of a file that has been deleted.

In Jan 2011 we deleted all of the hidden eclipse files from the repository and added them into the /.gitignore file.

So the idea is that those files can be generated automatically by the tool. However if local devs need to retrieve the original (last committed value version) this is the command to do it:


git show SHA-1:<full repository path>

The show command can show a specific file from a previous commit. And the standard labels of HEAD and HEAD^ ( for 1 commit before the current head) work:

git checkout core-1.4.x

cd jdk-1.5-parent/ddcalendar-parent/ddcalendar-examples

git show HEAD^:jdk-1.5-parent/ddcalendar-parent/ddcalendar-examples/.project > .project

Identify which files were deleted on each commit

The git log --diff-filter=D can be used to show the commits backward in time from the current HEAD where a file was deleted.

The --name-only option can be used to show the file names that were deleted for each commit

git log --format=oneline --diff-filter=D --name-only

8f3e43a68816772f3ba6b696ca768c063cdb94d0 push code cleanup
jdk-1.6-parent/push-parent-jdk-1.6/README

Here we can see that with commit 8f3e43a the file was deleted. There for it existed in the previous commit (8f3e43a^) and we can show the content like this:

git show 8f3e43a68816772f3ba6b696ca768c063cdb94d0^:jdk-1.6-parent/push-parent-jdk-1.6/README

A clone of wicketstuff-core/push-parent project.
The aim is to upgrade it to latest Cometd and Jetty versions.

Clone this wiki locally