Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I call git diff on the same file between 2 different local branches?

Is there a way to check the difference between the working directory in my current branch against the working directory of another branch in a specific file? For example, if I'm working in branch A on file 1, I want to compare the difference with file 1 on branch B.

like image 735
akantoword Avatar asked Jul 29 '16 17:07

akantoword


People also ask

How can I find the difference between two commits in a file?

To see the changes between two commits, you can use git diff ID1.. ID2 , where ID1 and ID2 identify the two commits you're interested in, and the connector .. is a pair of dots. For example, git diff abc123.. def456 shows the differences between the commits abc123 and def456 , while git diff HEAD~1..

Can you git diff a specific file?

The git diff command returns a list of all the changes in all the files between our last commit and our current repository. If you want to retrieve the changes made to a specific file in a repository, you can specify that file as a third parameter.

Can git work with two branches at once?

You can have many branches in your repository, but only one of these will be "checked out" as the working-tree so that you can work on it and make changes. git worktree adds the concept of additional working trees. This means you can have two (or more) branches checked-out at once.


2 Answers

Use the git diff branch branch filename syntax:

git diff branchA branchB -- file.cs 

put the two names of your branches and optionally use the -- filename option to specify one file! Good luck, let me know if you have issues.

like image 67
Patrick Murphy Avatar answered Sep 30 '22 17:09

Patrick Murphy


The following will help if you want to compare different files in two branches

git diff develop:foo.txt master:bar.txt 
like image 22
arulraj.net Avatar answered Sep 30 '22 18:09

arulraj.net