Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

magit: how to diff the same file between two different commits on the same branch?

Tags:

git

emacs

magit

How can I get the diff between two commits of the same file using magit?

Directly form git one can do this. But I don't know how to do it from within magit. From magit-status it seems that d and D returns the diff of the whole repository. This is very problematic for me as the repository is huge and it causes magit (and in turn emacs) to become unresponsive. Is there a way to ask magit to restrict the search to only one file from the repository?

I also tried, in the magit-status buffer to do : diff $start_commit..$end_commit -- path/to/file. This works, but the output is a simple buffer without any highlighting nor any folding options...

like image 245
Dror Avatar asked May 15 '13 11:05

Dror


People also ask

How do I compare files between two commits?

You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch.

How do I get the diff of a file in git?

By executing the git diff command, we can see the differences between these two files. By default, the git diff command produces a diff for all files between the latest commit and the current state of the repository.

How do I compare two files in different branches?

Overview. The git diff command is used to perform the diff function on Git data sources. For example, commits, branches, files, and so on. It can also be used to compare two files of different branches.

What does git diff head do?

The git diff HEAD [filename] command allows you to compare the file version in your working directory with the file version last committed in your remote repository. The HEAD in the git command refers to the remote repository.


1 Answers

You can also do M-x and magit-ediff-compare.

Then enter the SHA of the older commit and then the filename of the file you want to compare to HEAD, all on the same branch.

like image 173
Christoph90 Avatar answered Oct 25 '22 18:10

Christoph90