2

Reference to my original question

This is in continuation of that question I have a git repository in which I have a folder. In this folder multiple people makes changes. I have recently made few commits in that directory .

In one commit I added few lines of code and in next commit I removed those lines.
Lets call these lines as X.

I want to:

  1. view all changes that I have done in last 10 commits in that directory (ie changes done by me only) as a consolidated change where I see all changes in a file as a single space.
    Ie for me I should not see those lines X and should see each file single time only
    and

  2. view all changes that anyone has done in that directory in last 10 commits as a consolidated change where i see all changes in a file as a single space.
    Ie for me I should not see those lines X and should see each file single time only

Community
  • 1
  • 1
MAG
  • 2,841
  • 6
  • 27
  • 47
  • Could you please give some examples? Because IMO Git can't provide such a function out of box. Since each commit is a patch - a delta - to the file at the previous commit Git can't leave commits (of other authors) away if you make a diff of a commit range. Say you filter for author `B`: when author `B` changes a line that `A` has introduced before, Git can't ignore that change of `A`. This does not mean that an external tool (that you'll probably have to write on your own) could extract the information you want to know. – try-catch-finally Aug 16 '14 at 13:04
  • Without seeing an example I don't like to give a complete answer, so I'd just add this comment... While `git diff` can't filter for authors, `git log` can. It can also show the "patch" that the commit is made of. So with pure linux/unix shell scripting you could extract kind of per-author patch: `git log --oneline -p --author="Elmo" HEAD~10..HEAD | grep '^[+-][^+-]'` – try-catch-finally Aug 16 '14 at 13:09

2 Answers2

1

A git diff is more suited than the previously suggested git log then:

git diff @~10 @  -- path/to/folder
or
git diff HEAD~10 HEAD  -- path/to/folder

(with @ being a shortcut for HEAD, git 1.8.4+)

Note: as try-catch-finally rightly points out, this won't work regarding author: authorship can be filtered at the commit level, not so much at the patch level.
That is why my answer to the previous question used git log --author=xxx -p.

But to get the patches in one consolidated result though, git diff remains the right tool.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Error : fatal: ambiguous argument '@~10': unknown revision or path not in the working tree. Use '--' to separate paths from revisions – MAG Aug 16 '14 at 12:27
  • @MAG what git version are you using? Try and replace `@` with `HEAD` – VonC Aug 16 '14 at 12:27
  • @MAG that is... ancient ;) Anyway, @ is only available form 1.8.4+ (July 2013). Replace `@` with `HEAD` and it will work. – VonC Aug 16 '14 at 12:29
  • -1 That doesn't fullfill the requirements writen in the question. And even [Git 1.8.4 does not have](http://www.git-scm.com/docs/git-diff/1.8.4) an `--author` option. But the main thing is that you've answered within 30 minutes and ... just got the check. :) – try-catch-finally Aug 16 '14 at 12:46
  • @try-catch-finally I agree, I was giving a quick fix to get all the changes in one result (`git diff`). The git log you mention in your comment is what I was using in [MAG's previous question](http://stackoverflow.com/a/25339642/6309) – VonC Aug 16 '14 at 13:12
0

If you have one commit that adds files and another commit that removes them, you may want to consider interactive rebasing to squash those two commits together which will effectively remove the 'inconsistent state commit' that you probably want to eliminate.

Bring up the interactive rebasng editor with:

$ git rebase -i HEAD~10

Note that "~" in HEAD~10 is a 'squiggly' not a dash !

More info at http://git-scm.com/book/en/Git-Tools-Rewriting-History

Michael Durrant
  • 93,410
  • 97
  • 333
  • 497