Dumas45
Dumas45

Reputation: 521

Git diff between two commits in the same remote branch

How to get git diff between two commits in a remote branch?

For example I have remote branch remotes/origin/some-remote-branch. The remote branch has commit which I am interested on. So I want to get diff for that commit and store it in a local file.

I have cloned repository locally. But locally I checked out another branch 'some-another-branch' so I have many uncommitted files locally in 'some-another-branch'. So, I do not want to check out to remotes/origin/some-remote-branch because I am working with other branch. I just want to get diff from remotes/origin/some-remote-branch for particular commit and store it to a file.

Upvotes: 1

Views: 1497

Answers (2)

Nghia Bui
Nghia Bui

Reputation: 3784

To see what changes in commit2 compared to commit1, run this command:

git diff commit1 commit2

The output is a patch in which when we apply it to commit1, we have commit2. Thus, the order of the two commits in the command above is important.

In your example, you need to run:

git diff HEAD particularcommit

Just in case you don’t know HEAD: it is your current commit - the commit that you have checked out.

To save the output patch to a file, just append > file.patch to the command.

Upvotes: 0

Related Questions