0

While merging into the master branch it merges files that are already merged in master via different branch

Master branch M Feature branch f1,f2,f3

M <-f1
M<-f2
M<-f3

git clone http://test.com/test.git git checkout M

Open file in PHPstorm .It asked to Open project .clicked on confirm

git checkout -b f1
git status 
# it shows all file as modified even only file1 is updated

Open desired file file1 did the modification and saved it

git commit file1 -m 'f1 branch' 
git push -upstream f1
 git checkout M 
git merge f1 

git log -1 --stat

shows only 1 file file1 it merges file1 git push. The process is done properly but when tried same with branch f2. it merges file1 and file2 same goes for push where I am going wrong. But on each merge in master, it pushes previous branches files

Step where actual issue Occurs

git checkout -b f2

Open file2 in phpstorm modify and save the file

git status  

All files are shown as modified whereas only file2 was actually updated

git commit file2 -m 'test for f2'
git push -upstream f2
#push only file 2
git checkout M
git status
o/p Your branch M
your branch is ahead of 2 commits
git merge f2
#it merges file1 and file2
git push
#it pushes file1 and file2 

My 2 questions:

  1. How to open the project that is under git repository via PHPstorm. Is it the main cause to show all files as modified
  2. What wrong i am doing in merge or is there any method to just merge few files and push only few files in main branch.

Had taken reference from How can I merge two branches without losing any files?

Have updated the question is it clear

  • It is really unclear what you are trying to do. Are you able to clarify your question? – Burgi Mar 01 '19 at 11:30
  • Try to have a look why you're seeing every file as being modified. Check how you setup git to handle line endings, what PHPStorm uses and what's in the files after a checkout. – Seth Mar 01 '19 at 12:14
  • @Burgi is it clear now? Actually, i am trying to merge different files from different branches to master. It worked well in first merge and push. But while merging the second branch it had merged files that were already merged in the previous branch. – insoftservice Mar 01 '19 at 12:15
  • @Seth that's my question does phpstorm modifies the files. As i have just open the folder in it have not done any git settings as i don't know about it . Same if pulled on my colleagues laptop which has phpstorm has no issue. – insoftservice Mar 01 '19 at 12:18
  • You are the one on the computer. You will have to compare those files. Nobody can do that for you. Especially since your git settings also matter and only you know how you set it up. Grab the file, do a checkout, grab it again and compare it with your favorite tool. Are they different? If so either your editor or git modifies the file. – Seth Mar 01 '19 at 12:30
  • None of them are modified – insoftservice Mar 01 '19 at 12:32
  • Check if line endings in the file are different if git shows them as modified (e.g. using `xxd` to produce a hex dump). `git diff` should also show you how the files differ (if all lines are shown as changed, that's pretty good evidence that line endings were changed) – knittl Mar 01 '19 at 16:49
  • If you merge `f1` into `M` and later merge `f2` into `M` (already containing changes from both `f1` and `M`), why would you think that the changes of `f1` would disappear after the second merge? (If I understood the question correctly. It is still unclear what you are trying to do) Can you provide a MWE? (with ALL the steps and executed commands. Use `echo` to write files, show all commands and git commands in sequence, then we might be able to identify the problem) – knittl Mar 01 '19 at 16:52
  • i am not saying that file merge in f1 will disappear but it also won't show that it has got merged via branch f2. have shown the executed commands in my question its same. what is MWE ? . There is no issue of data missing or overriding. – insoftservice Mar 01 '19 at 17:01
  • MWE = minimal working example. All the necessary steps to reproduce your problem. That includes your first `git init` command and the steps required to create/edit your files (you can fake that with `echo` as stated above). You start your example with `checkout -b` and state that all files are shown as modified. Were the modified before switching branches? That's expected. Do they mysteriously show up as modified (how? did you check out the branch again, did you open them in some editor, etc.?) Please show all the steps so that we can help you. – knittl Mar 01 '19 at 23:01
  • Also, you write as comment in your second code block "push only file 2" – you cannot push single files with Git. You can only push branches and when pushing a branch, all commits that are parents of branch will be pushed, including all files from those commits. – knittl Mar 01 '19 at 23:02
  • command what i use to push is sudo git push -upstream feature/branch name. Have tried to add the exact steps what i do. Yesterday i had push branch f1 and thought it would merge branch f2 files but it allowed me to push with basic push command. sudo git push and it went properly ya there was a conflict with the master but that can be taken care – insoftservice Mar 06 '19 at 15:58
  • @insoftservice I hate to say it, but I think there's a big misunderstanding how branching and merging works in Git. Have a good read of the section on branching and merging in the Git book first: https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging – if this does not answer your question, try to rephrase it again :) I'm still having problems understanding what your exact problem is. It looks like everything is merged as it is supposed to (see my comment above about all previous commits being taken into account when merging. – knittl Mar 08 '19 at 19:43
  • as per ur link figure 21 and 22 works perfectly fine. Please consider file in branch iss53 is knittl.html and not index.html. Now when i merge iss53 . It not only shows that knittl.html is merged from iss53 but it also displays index.html which was actually present only in branch hotfix. Technically it should show that file index.html is from branch hotfix and knittl.html is from iss53 when merged in master. But it shows index.html in hotfix and in iss53 it shows knittl.html +index.html . Hope its now clear – insoftservice Mar 08 '19 at 20:25
  • @insoftservice merging is like addition. Later merges do not magically undo previous merges. If you have 1 (master) and 2 (hotfix), then merge them you get 1+2 (= 3, git checkout master; git merge hotfix). You are still on master (now 3). If you now merge 4 (iss53), your result will be 7 (3+4, git checkout master; git merge iss53), not 5. Why would it be 5? You merged hotfix before, now all changes of hotfix are contained in master. – knittl Mar 09 '19 at 09:56

0 Answers0