search

Home  >  Q&A  >  body text

How to use Git to view differences in code that is about to be pushed

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.

漂亮男人漂亮男人2874 days ago881

reply all(6)I'll reply

  • 怪我咯

    怪我咯2017-05-02 09:25:16

    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?

    reply
    0
  • ringa_lee

    ringa_lee2017-05-02 09:25:16

    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.

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-02 09:25:16

    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...

    reply
    0
  • 迷茫

    迷茫2017-05-02 09:25:16

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

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-02 09:25:16

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

    reply
    0
  • 为情所困

    为情所困2017-05-02 09:25:16

    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

    reply
    0
  • Cancelreply