How to use Git to view differences in code that is about to be pushed
漂亮男人
漂亮男人 2017-05-02 09:23:16
0
6
882

Usage scenarios for this problem

For example, you modified the code locally and submitted it more than 20 times. Now you want to push these codes, and you want to check the code again, but you need to count, which files have been modified in these 20 commits? What changes were made to each file?

At this time, you need to use this command to easily view the list and differences of all modified files.

Ask God for answers

It is best to inform in two forms:

  1. List all modified files, but do not show differences.

  2. Lists all modified files and displays all modification differences.

漂亮男人
漂亮男人

reply all(6)
刘奇

This is the most appropriate answer I have found so far:

git diff origin/分支名...HEAD
git diff origin/分支名...HEAD --name-status

I was stepped on for no reason, and I don’t know who stepped on it. I hope to stand up and have the ability to provide simpler and easier answers. What’s the psychology of stepping on others when you can’t answer?

左手右手慢动作

git log You can specify time range, start and end commits, file paths, branches/labels and other conditions, and you can filter the output results to easily meet your first requirement.

git show 或者 git diff can meet your second requirement, the parameters used will be different.

I won’t tell you the specific commands, just read the documentation yourself.

But I can give you a trick. If you think the span of commits is a problem, you can create a new temporary branch, and then perform interactive rebase (squash all commit) forward to the initial commit you want to compare. In this way, you need There are only two commits to compare, one is the starting point, and the other is the sum of the subsequent n commits.

我想大声告诉你

In fact, I think I should download a Github client. It is very intuitive and convenient to use. It has been updated recently. The workflow diagram of the new project. I am using the Windows version. I don’t know about the Mac version...

迷茫

For file differences, use the client....sourceTree

習慣沉默

git diff commit1 commit2 --name-status
git diff commit1 commit2

为情所困

For a comparison of the committed content, see @910JQK’s answer

Contents that have not been committed but have been added can be used git diff --cached

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template