# Finding Which Git Commit Deleted a File Section
Suppose you want to find out which commit deleted a section of a file. Follow the following steps to find that out.
To find out which commit merged a file section see [[Finding Which Git Commit Merged a File Section]]
## Step 1: Find the last commit that contained the code
Suppose the removed code was in lines 514,+5 which existed in commit `05dd7f0`. The first step is the following command
```shell
git blame -L 514,+5 --first-parent --reverse 05dd7f0..HEAD src/csharp/RaceCon/RaceCon/GuiLayer/MainView.Ribbon.cs
```
If you get the following error:
> fatal: --reverse --first-parent together require range along first-parent chain
it means the commit you used cannot be reached by traversing HEAD using first parent only. The solution is simple, simply replace it with the merge commit:
```shell
git find-merge 05dd7f0 HEAD
```
and take it from there.
The first step will produce the following output which tells you which commit still had the code in question (in this case `4353c14be02`). We're looking for one of the neighboring children.
```
4353c14be02 (Jochen Nachbaur 2019-08-20 15:03:59 +0200 514)Device deviceToOpen =
4353c14be02 (Jochen Nachbaur 2019-08-20 15:03:59 +0200 515) selected?.getParent<Device>() as PlatformLogger
4353c14be02 (Jochen Nachbaur 2019-08-20 15:03:59 +0200 516) ?? devicesOfcontext.FirstOrDefault(d => d is PlatformLogger pl && pl.EnableLogging)
4353c14be02 (Jochen Nachbaur 2019-08-20 15:03:59 +0200 517) ?? devicesOfcontext.FirstOrDefault(d => d is PlatformLogger);
48e2ac3fa20 (Nikola Milekic 2020-02-27 15:09:36 +0100 518)
```
## Step 2: Find the child of last known commit that deleted it
Execute the following with the commit found in the previous step
```shell
git log --pretty=oneline --ancestry-path --first-parent --reverse 4353c14be02..HEAD
```
The first line of the output is the commit that removed the line
## Step 3 (optional): Find specific commit within merge request
Optional: If the commit retrieved from the previous step (`954f52794a`) is a merge, run the following to find out the last good commit inside the merge request (you started out with commit `05dd7f0` (commit where code existed)).
```shell
git blame -L 514,+5 --reverse 05dd7f0..954f52794a^2 src/csharp/RaceCon/RaceCon/GuiLayer/MainView.Ribbon.cs
```
It's important here to pick the correct merge branch (second parent in example above).
Now with output from the above rerun `git log`:
```shell
git log --pretty=oneline --ancestry-path --reverse bf32dec4f46..HEAD
```
## Dealing With Large Merge Requests
It's possible that step 3 won't work if you're dealing with a large merge request where the mainline was merged multiple times to fix merge conflicts (and the commit you're starting with is somewhere in the middle).
In this case you need to repeat the whole procedure from step 1 but with different start commits: the final commit to the branch before it was merged into the mainline (easy, that's simply the second ancestor of the commit retrieved from step 2) and the first commit of that merge request, finding which will be more difficult.
The following command will output all commits in the merge request (say the merge request from step 2 is `954f52794a`):
```shell
git log --pretty=oneline --first-parent 954f52794a^2
```
Navigate the list returned from the previous commit to find the first commit of the merge request (say that's `08d923a715f`).
Now repeat the procedure outlined above but instead of entering `05dd7f0..HEAD`, enter `08d923a715f..954f52794a^2`