简体   繁体   中英

list only files deleted by us, added by us, deleted by them, etc in git rebase

I'm working through a git rebase , and it's been a number of times where I've had to make decisions about files deleted by us, added by us, deleted by them, etc.

Is there a way to get git to show me only one subset of these files? This way, I can pipe the output into xargs and deal with a set of files all in one go.

In other words, if I have this:

    added by us:     core/tests/Drupal/Tests/Component/Annotation/Doctrine/Fixtures/AnnotationWithVarType.php
    added by us:     core/tests/Drupal/Tests/Component/Annotation/Doctrine/Fixtures/ClassWithConstants.php
    added by us:     core/tests/Drupal/Tests/Component/Annotation/Doctrine/Fixtures/ClassWithInvalidAnnotationTargetAtClass.php
    added by us:     core/tests/Drupal/Tests/Component/Annotation/Doctrine/Fixtures/ClassWithInvalidAnnotationTargetAtMethod.php
    added by us:     core/tests/Drupal/Tests/Component/Annotation/Doctrine/Fixtures/ClassWithValidAnnotationTarget.php
    deleted by us:   vendor/behat/mink/.gitattributes
    deleted by us:   vendor/behat/mink/.gitignore
    deleted by them: vendor/doctrine/annotations/CHANGELOG.md
    deleted by them: vendor/doctrine/annotations/phpstan.neon
    added by them:   vendor/justinrainbow/json-schema/phpunit.xml.dist

I would want to be able to specify, for example, added by us , and see only

    core/tests/Drupal/Tests/Component/Annotation/Doctrine/Fixtures/AnnotationWithVarType.php
    core/tests/Drupal/Tests/Component/Annotation/Doctrine/Fixtures/ClassWithConstants.php
    core/tests/Drupal/Tests/Component/Annotation/Doctrine/Fixtures/ClassWithInvalidAnnotationTargetAtClass.php
    core/tests/Drupal/Tests/Component/Annotation/Doctrine/Fixtures/ClassWithInvalidAnnotationTargetAtMethod.php
    core/tests/Drupal/Tests/Component/Annotation/Doctrine/Fixtures/ClassWithValidAnnotationTarget.php

And then the same with the other combinations.


The closest I've gotten with with ls-files :

$ git ls-files -u

100644 31f22a4cec3c5e170077bcfebc2208d2b37fe075 2       core/tests/Drupal/Tests/ComponentAnnotation/Doctrine/Fixtures/ClassWithInvalidAnnotationTargetAtClass.php
100644 9ee0a27f86c900240e781ab103e1bdc6fab957ba 2       core/tests/Drupal/Tests/ComponentAnnotation/Doctrine/Fixtures/ClassWithInvalidAnnotationTargetAtMethod.php
100644 505aa27a131e0090af5f2416f240e0cbcee3ff84 2       core/tests/Drupal/Tests/ComponentAnnotation/Doctrine/Fixtures/ClassWithValidAnnotationTarget.php
100644 010e9b933b548c96cb7618844ff160f5e800f6e1 1       vendor/behat/mink/.gitattributes
100644 9db3888aebea01ede0d8a42e87ddb7b430310f90 3       vendor/behat/mink/.gitattributes
100644 66de342a111ac61c9bcba7d19b2372399c8502c3 1       vendor/behat/mink/.gitignore
100644 e3305a8383c4cd841083be61e1b5dcfa31cc4ca0 3       vendor/behat/mink/.gitignore
100644 0b0ba1a71d8c725fa394861e87542b0e612cf738 1       vendor/doctrine/annotations/CHANGELOG.md
100644 c09ebe60107ef2d316321cef1c1bccf5c0545df7 2       vendor/doctrine/annotations/CHANGELOG.md
100644 be267e611cc7a8c7e105f17801e8f2512f56b8fc 1       vendor/doctrine/annotations/phpstan.neon
100644 d2b79a7fd65549181ea808290b13b32dbb78bce0 2       vendor/doctrine/annotations/phpstan.neon
100644 0136d8edcc23976ae263b15acf5512ef57bd9c9e 3       vendor/justinrainbow/json-schema/phpunit.xml.dist

The second column of the output has a number, which seems to indicate the action, and whom it was taken by. But, I don't know the name of that column or file property to reference it. Some files are represented twice, I suppose from different commits, but I'm not sure how git ultimately decides which status to go with for the file.

I also looked at --diff-filter , but it only seems to be able to show me files that are changed at all, not by whom.

$ git diff --name-only --diff-filter=U
core/tests/Drupal/Tests/Component/Annotation/Doctrine/Fixtures/AnnotationWithVarType.php
core/tests/Drupal/Tests/Component/Annotation/Doctrine/Fixtures/ClassWithConstants.php
core/tests/Drupal/Tests/Component/Annotation/Doctrine/Fixtures/ClassWithInvalidAnnotationTargetAtClass.php
core/tests/Drupal/Tests/Component/Annotation/Doctrine/Fixtures/ClassWithInvalidAnnotationTargetAtMethod.php
core/tests/Drupal/Tests/Component/Annotation/Doctrine/Fixtures/ClassWithValidAnnotationTarget.php
vendor/behat/mink/.gitattributes
vendor/behat/mink/.gitignore
vendor/doctrine/annotations/CHANGELOG.md
vendor/doctrine/annotations/phpstan.neon
vendor/justinrainbow/json-schema/phpunit.xml.dist

Of course, I could use grep and sed or something to filter the lines and extract the text, but I wonder if there is a git-only way to solve this problem.

List "deleted by us":

git status --porcelain -uno | sed -n 's/^DU //p'

A linked answer: https://stackoverflow.com/a/69558302/1300170

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM