Question: I have a commit where a file is renamed. Is there any possibility to get the new file name from the old file name and the commit key?

Example: `file.php` is renamed to `filex.php` at commit `5119afae52e5ae08ca8e378e00895d824a179f03`.

I'm searching for something that returns `filex.php` from the information about `5119afae52e5ae08ca8e378e00895d824a179f03` and `file.php`.

Answer: 
The following bash script will do the job:

**Usage**:

```
new_name_of_renamed_file <oldname> <commitid>

```

**new\_name\_of\_renamed\_file**:

```
#!/usr/bin/env bash

if [ $# -ne 2 ]
then
    echo "Usage: new_name_of_renamed_file <oldname> <commitid>"
    exit 1
fi

pattern="^rename from ${1/./\\.}\$"
git diff -M100% "$2"^.."$2"|grep -A1 "$pattern"|tail -n1|sed 's/^rename to //'

```

**Notes**

* The script detects only exact renames. If you are interested in renames where some modifications were made to the renamed file you can pass a corresponding similarity threshold to the [`git diff -M`](https://git-scm.com/docs/git-diff#git-diff--Mltngt) command.
* If the file `oldname` doesn't exist in the parent of `commitid` or was not renamed in that commit, then nothing is output.
If you run :

```
git log --oneline -- file.php

```

you will see a list of all the commits that modified this `file.php`.

The most recent of these commits (the one on top) will be the one when `file.php` has been renamed to `filex.php`.

You can confirm this by running `git diff <hash>`, where `<hash>` is the commit id you found using `git log`.

(note : this would also work without the `--oneline` option ; the `--oneline` option gives you exactly one line per commit, which makes it maybe easier to understand the whole list.  

You can also try `git log --oneline --graph ...`)