0

I'm stuck at the following problem:

This is what I want:

  • a git command, that I can use to show the 'US' changes
  • it should work like status, (show what I did) in comparisation to the remote

This is what I tried:

  1. git diff [in JGit -> diffentry] with many options e.G. master..branchName
  2. I tried to find a git status cmd, that does work with 2 commits.
  3. I watched through the whole diffEntry[JGIT] methods to find a method to get my desired Output
  4. I googled for JGit methods, that will show me my desired Output

    To 1. -> The problem is : When I change a file on remote, the git diff command shows the file as 'M' for modified, but the user did not modified it, it may be true, but is not what I search

    To 2. -> git Status is something I'd like to use, because it shows exactly what I want.... but only from index to head...

For what?

I want a list from all files that the User had modified/added/deleted so I can iterate through it and put head informations in every file, just before he pushes the file.

Hows the workflow?

I clone a branch, do N-commits and now I want to push. Every file in this N-commits must be modified. (and that's the Problem with this modified, if it's modified in the remote branch, but not locally, than I should not touch it with my script, but I have no way to differentiate between this two)

€dit: Additional Infos

git diff-index does nearly what I want. The problem: I need to filter only 'our' changes. So if a file is modified on remote, I dont want to see it. I want to see MY modified files.

Keey
  • 199
  • 1
  • 15
  • Indulge me if you will. Are you just looking for a way to see the differences between your local changes and the remote? – Hexana Mar 22 '16 at 09:38
  • Yes, but with the following restriction: git diff shows a file as Modified if it was modified on the remote branch, but I want to show the User only the files HE modified/deleted/added, so it's confusing, if he sees a modified file, that he had not touched. – Keey Mar 22 '16 at 09:40
  • I am not 100% clear in what you are asking but here are some suggestions. git diff origin/master will give you the diffs between your local branch and the remote. You can also do: git fetch origin if you know there are changes on the remote, and to see the differences you do git log -p HEAD..origin. Another possibility to find differences is $ git diff --name-status master..branchName (obviously changing the names relevant branch names). I've got a feeling the last one might be what you are looking for? – Hexana Mar 22 '16 at 09:47
  • The Problem with those calls is, they do not differentiate. Especially the last one is NEARLY what I want. It shows my current modificated files. But now the Problem: It shows me a file as modified, if I have not modified it, but it was modified on remote, and there is no way I can see which side modified it. I want to see user changes ONLY (modified, deleted, added). – Keey Mar 22 '16 at 09:52
  • did you try git diff-index , it should compare only against the index so not the remote; you can also look at git diff-files – Frederic Henri Mar 22 '16 at 10:02
  • git diff-index does the same. A file is marked as modified, even if the local branch did not modify it. (It is correct from git side, but not what I want, I want to see only my own modify) diff-files is only shows to the last commit. But thanks! I looked at the help page for the diff-index and what I need is a Filter to show only MY side of Modify/delete/add - is this possible? – Keey Mar 22 '16 at 10:11
  • but if you do git fetch before doing the diff, you should have only your change – Frederic Henri Mar 22 '16 at 11:48

1 Answers1

0

If you want to see changes on Your side only, you should update the index before you diff, so run git fetch <remote> <branch> and your index tree will be up to date, after this you can run git diff-index <branch>

you can add the --diff-filter=ADM if you want to select only files that are Added (A), Deleted (D), Modified (M)

Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
  • I just tested it and it does not work: Heres what I've done: -OTHER PC- (on another PC than mine) // 1) git clone 2) git checkout develop 3) file modify 4) git commit -a -m "test" 5) git push -MY PC- (on my pc, current branch master) // 1)git fetch origin develop 2)git diff-index --name-status origin/develop And the modified file from the other pc is shown.. I guess I do something wrong Thanks for your help so far – Keey Mar 22 '16 at 12:41
  • once you fetch origin, just diff against the local index `git diff-index --name-status` – Frederic Henri Mar 22 '16 at 13:11
  • If I write this command exactly like this, I'll get an info text on how to use the command. Maybe it's because we use git 2.6? – Keey Mar 22 '16 at 13:31