Previous Commit to another for Deleted/Moved/Renamed File

ScientiaEtVeritas

I'm using the following command to get the key of the previous commit to another commit, in context of a file:

git log --max-count=1 --pretty=format:'%H' COMMITKEY~1 -- path/to/file

But in case of a deleted file it will return an error: stderr: 'fatal: ambiguous argument 'path/to/file': unknown revision or path not in the working tree.

So I tried something like this:

git log --max-count=1 --pretty=format:'%H' --all --full-history COMMITKEY~1 -- path/to/file

This actually returns a commit key, but always the newest, not the previous one. Even if I change the revision to COMMITKEY~2 or something else, it will return the same commit key.

What's wrong here?

Vampire

Are you sure you used -- with the first command?

That your second command does not work is easily explained by your usage of --all, as --all is equivialent to listing all refs manually, so you will of course always get the latest commit returned.

Actually you can abbreviate --max-count=1 to -1, so using git log -1 --pretty='%H' commit-ish~ -- path/to/file is enough and will also work.

You only get the message 'fatal: ambiguous argument 'path/to/file': unknown revision or path not in the working tree if you are not using the -- that tells git that there is a path following, as then Git does not know whether this should be a ref that cannot be resolved or a path that might exist in the history.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Git: modify file in a previous commit

From Dev

Compare file to another file in another commit

From Dev

How to revert changes to 1 file in previous commit

From Dev

Undo removal of file from a previous commit

From Dev

File size limit of 100.00 in previous commit

From Dev

Checkout all files from a previous commit with a certain file name

From Dev

Removing file from .git directory from previous commit

From Dev

Git Merge previous commit

From Dev

How to deploy previous commit?

From Dev

See previous commit in Github

From Dev

Checking out to another commit with git while reading the file

From Dev

Submitting another ipa file right after previous submission

From Dev

smartgit delete commit and return to previous commit

From Java

Break a previous commit into multiple commits

From Java

How to stash my previous commit?

From Dev

Revert to previous commit Windows Azure

From Dev

How to rollback everything to previous commit

From Dev

how to undo a hundreds previous commit

From Dev

How to checkout a previous commit with TortoiseSVN

From Dev

Revert to previous commit Windows Azure

From Dev

how to undo a hundreds previous commit

From Dev

Revert Code to Previous Commit in Master

From Dev

bitbucket rebase a branch on a previous commit

From Dev

Checkout previous commit and attach HEAD to it

From Dev

Programmaatically fixup last commit into previous

From Dev

Push changes based on previous commit?

From Dev

Git: how to melt a commit to another commit?

From Dev

git replace a commit by a commit from another branch

From Dev

Save a file under another name exactly as it was on a specific date/commit without changing branch or reverting

Related Related

HotTag

Archive