1

I am working on library_backend project and it is git repository which have 2 branches :

  1. master
  2. multilanguage.

i have made some changes in multilanguage branch and pushed it to its remote branch and after it i want to check some functions on master branch.

so i have switched to master branch and after checking i have switched back to multilanguage branch but now it has modified file which is books_model.php, how can it has modified file if i have pushed it some seconds ago?

You can see what i have done after pushing to remote branch as below:

ABC@ABC-PC MINGW64 /c/xampp/htdocs/library_backend (multilanguage)
$ git checkout master
Switched to branch 'master'
M       application/models/api_model/books_model.php
Your branch and 'origin/master' have diverged,
and have 4 and 10 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

ABC@ABC-PC MINGW64 /c/xampp/htdocs/library_backend (master)
$ git checkout multilanguage
Switched to branch 'multilanguage'

ABC@ABC-PC MINGW64 /c/xampp/htdocs/library_backend (multilanguage)
$ git status
On branch multilanguage
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   application/models/api_model/books_model.php

no changes added to commit (use "git add" and/or "git commit -a")
Haritsinh Gohil
  • 5,818
  • 48
  • 50
  • If you have modified a work-tree file (and/or the copy in the index), and want to switch to a different commit without first committing the modified file, Git will often allow that. It just keeps the modified file in the work-tree (and index), and tells you that it did that. See also https://stackoverflow.com/q/22053757/1256452 – torek May 30 '19 at 00:50
  • @torek i know that but here i have switched to master instantly after pushing to remote so i have not modified any file. – Haritsinh Gohil May 30 '19 at 04:34
  • "Instantly after pushing" does not imply "have no modified files in the index and/or work-tree". `git push` pushes *commits;* what's in the index and work-tree are not commits and hence are completely irrelevant. – torek May 30 '19 at 06:52
  • yes you are right, i know @torek but i have added all the changes in my commit before pushing to remote, so there are not any modified files after push. – Haritsinh Gohil May 30 '19 at 07:21
  • That may be the case, but we cannot *see* that in your output above. What you need here is a [mcve]. (I can see that there is some difference between a work-tree file and its index copy, and I can guess at one of several possible reasons—e.g., a case-folding file system, or a discrepancy between some end-of-line setting and a committed file—but can't tell you which of these might actually be the case here, if any.) – torek May 30 '19 at 07:29
  • @torek, sorry but i can't reproduce it, but the additional info is that , you can see in my question in code part when i have switched to master branch it is showing `M books_model` under info, whereas switching to `multilanguage` has nothing like that, what does that mean , may be it can explain something. – Haritsinh Gohil May 30 '19 at 07:51
  • That's not really clear, not without a way to reproduce the issue. – torek May 30 '19 at 10:06

3 Answers3

0

Most possibly this change was already in place and you only pushed a commit containing other changes. This of course if you haven’t changed this file by mistake while you were on your local master branch.

Ali Ben Zarrouk
  • 1,891
  • 16
  • 24
0

You can see the changes occurred in the modified file by following command.

$ git diff application/models/api_model/books_model.php

This will generate result in green and red color for modified code.

Red color indicates code which has been deleted from file.

Green color indicates the code which has been added.

If you can see the changes that you have made here in the result of this command in green color, then you should go to your branch 'multilanguage' and add, commit, push that file again.

If you can not see the changes that you have made to the file or you do not want to commit it, then you can revert the changes by checking out to the same branch 'multilanguage' and firing this command.

$ git checkout application/models/api_model/books_model.php

Hope it helps you !

Shweta
  • 661
  • 6
  • 11
  • i have already done git diff, and the difference in file had been done by other user who is working on same repo, but the question is , the changes should have arrived when i have pulled from the remote branch and after it i have pushed on same multilanguage branch then after pushing i have switched to master and back to multilanguage , then how can it has modified file? – Haritsinh Gohil May 30 '19 at 05:39
  • This is unusual case then... I think you should focus on fixing it now by doing add commit, pull, push again. – Shweta May 30 '19 at 06:07
  • i have done it already, but i am wondering why it happended so i have asked the question? – Haritsinh Gohil May 30 '19 at 06:10
0

While the issue is not easily reproducible, you should test the new experimental command git switch (with Git 2.23+ only, Q3 2019): it would be less susceptible to automatic changes, using the option to discard changes:

git switch -f  multilanguage
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250