How to find shared files modified between git branches?

I have an upstream repository with some changes. I have local changes that I want to change to upstream changes. I want to know which files that I changed locally also changed upstream, so I can check the automatic merge. In addition, I would like to manually perform any merges during rebase.

+5
git
source share
4 answers

Expanded bit: for the first part of the question, create a new branch, automatically replace it there, and then compare it with your working copy.

git branch workBranch git commit #throw your locals into your own branch for a brief moment git branch testBranch git rebase otherBranch git diff workBranch 

You can also get away by simply doing "git diff origin / branchToMerge"

For the interactive part:

 git rebase --interactive. 

Set all the commits to "Edit", and you will go through each of them one by one, giving you the opportunity to see everything that has been done for this commit and edit it for your hearty content.

EDIT to reply to comment

OK, to strictly view the modified files, do:

 git log a0a0a0..b1b1b1 --name-only --pretty=oneline | egrep -v '^[a-f0-9]{40} ' | sort | uniq > lista git log a0a0a0..c2c2c2 --name-only --pretty=oneline | egrep -v '^[a-f0-9]{40} ' | sort | uniq > listb cat lista listb | sort | uniq -d 

This kludgery shell bit will only show you files that have been changed in both logs. For a0a0a0, use your common point. Replace the b1 / c2 strings with the tips of two diverging branches.

+4
source share

List of modified files

Since overflow / merging can take a long time, it is better to avoid unnecessary. There are many ways to see what has changed, depending on what information you need.

If you are interested in understanding which files have been modified, I suggest git-log :

 git log [--pretty=<format>] --name-only <common-branch>..<local-branch> 

You can use the --pretty option to get the necessary header information; <format> can be a variety of choices, including a custom field string - see the man page for more information.

The --name-only parameter is actually passed before git-diff , so if you don’t like the results per commit, you can go directly to the source:

 git diff --name-only <common-branch> <local-branch> 

Please note that branches are set differently for two teams.

You can also apply this to upstream changes by changing <local-branch> to <upstream-branch> and getting two file lists. I will leave this for you to figure out how you want to compare them, although the -f grep option may be convenient ...

Manual mergers

Autocracy beat me. If you did some smart processing based on git-log output, you could only edit the commits you saw with overlapping file changes. If you are merged rather than recharged, you should use the --no-commit option.

See also the configuration section of the git-merge man page. You might want to set merge.conflictstyle to diff3 so that you can see the source text as well as the changes on both sides.

If you are really desperate to suppress all attempts to automatically resolve conflicts, I believe that you can connect a dummy mergetool (via merge.tool and mergetool.cmd) that does nothing and returns a failure.

Having said all this, I also have to say that in my experience with git merges, I have seen a lot of conflicts, but I cannot recall a single incorrect automatic merge. I personally trust him to merge. Check on it after really should be a lot.

+12
source share

I know this is a really old topic, but we found that git diff -name-only returned too many false positive modified files if the two branches are too different. Here we use at work to execute a review code to commit a new branch against our feature branch (possibly already partially merged into feature branches).

being in our new_branch system and under * nix, we use this command:

 git show --name-only $( git cherry -v feature_branch | grep '^+' | awk '{ print($2) }' ) | egrep -v '^(commit |Author:|Date:|\s|$)' | sort -u 

replaces feature_branch with the name of the branch with which you want to check the modified files.

The advantages of this technology are that it really only sorts files modified by commits belonging to your branch that are not yet merged in your feature_branch.

If you want to check between two commits SHA1 and SHA2, you can also do:

 git show --name-only $( git cherry -v SHA1 SHA2 | grep '^+' | awk '{ print($2) }' ) | egrep -v '^(commit |Author:|Date:|\s|$)' | sort -u 
+1
source share

it will list the 20 best files on your thread that have changed most often

git log --pretty = format: --name-only | sort | uniq -c | sort -rg | head -20

0
source share

All Articles