Looking for more info from my Git diff command

你离开我真会死。 提交于 2019-12-25 18:44:37

问题


My basic git diff doesn't do a whole lot for me. Here I am diffing my master branch against the staging server's master branch:

(~/hbb.vm) debian $ git diff ..stage/master --name-only
sites/all/libraries/attachment_email/attachment_email.php
sites/all/modules/redirect/redirect.module
sites/all/modules/redirect/redirect.test
sites/all/themes/HBB/css/elements.css
sites/all/themes/HBB/templates/node--enterprise_blog.tpl.php

I would like to see info like:

  • has this file been added/modified/deleted?
  • on which branch the file has been added/modified/deleted?

EDIT: I am not interested in seeing all changes - I want something in between. A rich summary.


回答1:


You can use the following command to see a summary of the differences between your current branch and stage/master:

$ git diff --name-status ..stage/master
M       practice.txt
A       shazbot.txt
D       foobar.txt

where M stands for "Modified", A stands for "Added", and D stands for "Deleted".

If you want to see in which commits these files were modified, added, or deleted, you can use the log command instead, with the same --name-status argument:

$ git log --oneline --name-status ..stage/master
31b9628 Add shazbot.txt
A       shazbot.txt
e56da37 Merge branch 'develop'
790f3bf Revert "Revert "Merge branch 'develop'""
M       practice.txt
d9493e0 Merge branch 'master' into develop
8832960 Revert "Merge branch 'develop'"
M       practice.txt
2b82909 Merge branch 'develop'
2d41fb6 Fix bug 01
M       practice.txt
526bf16 Add feature 02
M       practice.txt
ba8700c Add feature 01
M       practice.txt
bb8ced2 Add practice.txt
A       practice.txt

Asking about which commits introduce changes is more reliable in Git than asking about which branches, because in Git, branches are just cheap labels that can be applied and removed from commits, and may no longer exist in any of the repos/remotes that you're using.




回答2:


What commits do they have in stage/master that I don't have locally:

git log ...stage/master --graph --decorate --cherry --name-status

What commits do I have locally that I haven't pushed to stage/master:

git log stage/master... --graph --decorate --cherry --name-status
  • --decorate -- shows tag and branch names beside commits
  • --cherry -- shows "=" instead of "*" on commits that are merged.

What's the symmetric difference, in term of commits, between the two:

git log ...stage/master --cherry-pick --left-right --name-status
  • --left-right -- shows "<" and ">" on commits to indicate whether commits are from left of ..., or right, respectively.

Also look at: git-log



来源:https://stackoverflow.com/questions/17996220/looking-for-more-info-from-my-git-diff-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!