I am trying to diff my local file with a GitHub repository before I submit a pull request, so I can see what will show up. Is there an accurate way of doing this?
I assume GitHub's compare tool manipulates Git's diff.
I am trying to diff my local file with a GitHub repository before I submit a pull request, so I can see what will show up. Is there an accurate way of doing this?
I assume GitHub's compare tool manipulates Git's diff.
Per the OP's comment that part of his "problem was Windows vs. Unix LFs", this should help:
You can use the following configuration command to tell git-diff to ignore the difference of the EOL code.
git config --global core.whitespace cr-at-eol
You can use: git diff remote/my_topic_branch my_topic_branch
Where my_topic_branch is your topic branch.
Important to remember: Git diff will show you diferences between two commited branchs ( remote or local).
Step 1) - Commit local
So the first step to do is make sure you have commited your local repository. You can run git status to see if there is any file left.
If you need to add a file run a git add {filename} or to add all files git add .. Then you can run a git commit -m "message" to commit you local files.
Step 2) - Fetch your branch from remote
You can fetch your remote using git fetch origin master. If you see a message like below, you are good to go.
branch master -> FETCH_HEAD
Note that origin is the repository and master is the branch within that repository.
Step 3 Check differences
Now you can either git diff --summary FETCH_HEAD or git diff origin/master master --summary too see your changes.
I just had a related problem where I wanted to get a quick overview of changes in a GitHub PR before merging it.
Basically I was only interested in knowing how many files were added, modified, or deleted in that PR. The PR had thousands of changes, which made the GitHub web UI useless.
If anyone has a similar problem, try doing this on your local machine:
git fetch origin branch as @HieroB suggested. This will get metadata about the latest changes in the remote branch without pulling all these changes locally.
git diff --name-status FETCH_HEAD > difflog.txt. Git will create a list of all files that were changed in the remote branch, and save the list to a file. The structure of the resulting file will be like this:
M files/file1.json
D files/file2.json
A files/file3.json
where the change marker M stands for "modified", D stands for "deleted", and A stands for "added. In each line, its change marker will be delimited from the file name with a tab character.
Open the file in a text editor, copy each of the 3 change markers along with their adjacent tab characters, and use your text editor's Find in file functionality to search for the marker's occurrences.