1

I am very new to git and I have been seeing this every once in a while.

For example:

  1. I work on my branch branch-A for few days (branch is created from develop fresh copy)
  2. I do git add . / git commit -m "blahblah" to stage and commit my changes
  3. Now I want to get latest changes from remote and merge it into my branch so I ensure I work on latest code
  4. to do so, I do git checkout develop to switch to my local develop branch, git status shows I'm behind 37 commits

    myMBPro:MyProj$ git status
    On branch develop
    Your branch is behind 'origin/develop' by 37 commits, and can be fast-forwarded.
      (use "git pull" to update your local branch)
    
    Changes not staged for commit:
      (use "git add/rm <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)
    

    and the list of deleted, untracked files follow

  5. git fetch origin, then git merge origin/develop while on develop branch shows:

myMBPro:MyProj user$ git fetch origin myMBPro:MyProj user$ git merge origin/develop Updating 799c6d7a..510c77ab Fast-forward .../Implementations/MyRenderer.cs | 39 ++-- ... etc

  1. I would typically now switch to my branch branch-A and do git merge develop to merge develop to branch-A but I typically do first git status to check all is OK. So, I stay on develop branch and do git status
  2. The problem is that I see git status reporting probably every single file in my project as changed (some as untracked, some as staged and some as ready to be committed).

```

myMBPro:MyProj user$ git status
On branch develop
Your branch is up to date with 'origin/develop'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

, and the list of files ready to commit, files not staged, and files that are untracked follows after this.

So, I end up with lots of files that I haven't even touched, nor modified, nor added now showing as being somehow modified by me. As a result, I am hesitant to merge them in my branch-A.

Any idea why is this happening? Is it even normal (but to me it does not sound normal that files I have not changed appear as they are changed by me and now I need to start tracking them, stage and commit them.

I am on MacBookPro, using git from terminal and also using SourceTree

cd491415
  • 823
  • 2
  • 14
  • 33
  • Was there a merge conflict? – Marc Nov 07 '18 at 19:58
  • No, no conflict, all merge was fast-forward – cd491415 Nov 07 '18 at 20:06
  • 1
    Is it possible you added some files on your branch? I can't recall the exact behavior of `git add .`, but is it possible that this doesn't add untracked files? – Andy Nov 07 '18 at 20:40
  • 1
    Check your line ending settings, it's possible the endings are stored in the db with windows line endings – LightBender Nov 07 '18 at 21:41
  • @Andy yes but that was on my branch. And I committed these to my branch, then switched to develop to do what I described above. Adding files on another branch and committing them to that branch should have no effect in that case – cd491415 Nov 07 '18 at 22:18
  • @LightBender That is possible. Where and how do I confirm/check that? Thanks – cd491415 Nov 07 '18 at 22:19
  • if you run a diff, if the original has a lot of `^M` characters in it, you've got windows line endings in the repo. The solution will largely depend on the team you're working with, but you will most likely need to fix the files in the repo or change the autocrlf option to false. – LightBender Nov 07 '18 at 22:23

1 Answers1

1

Are you sure that you did git commit immediately before git checkout develop? The only way that I know this can happen if your working directory is dirty before you checkout develop and pull.

Sure, there might be line ending problems, but this still doesn't really explain the issue. An important aspect of git merge is that it must commit. It is guaranteed to commit if there are no conflicts, and the only way it wont commit is if there are merge conflicts (Which can leave you in that state of variously staged and unstaged files). If you aren't getting merge conflicts (Meaning you see the words fast-forward), then there seems to be only one possibility:

Say you're working on branch A. Then you commit. Then, you change a couple of files (Or, they are changed automatically by some software you have running at the same time). Then, when you git checkout develop, you end up copying your index. The index being the set of all of the changes you've made since the most recent commit. You can checkout another branch and your index will follow you. This seems to be the only thing, as far as I'm aware, that could cause what you're experiencing. If the merge affects files that part of your index, then the merge will fail. However, it's possible for the merge to succeed if it's a simple fast-forward that misses your index, which will cause your index to be shown on top of the most recent commit.

For the future, try running git status before git fetch origin; git merge origin/develop. If you're still running into trouble, you might have to copy-paste what's in your terminal so we can read it.

Also, make sure to only have source code and build scripts in the repo, and to .gitignore any files that might be created by vim, your IDE, your build scripts, the running executable, etc. Any of those files are likely going to change constantly.

Nicholas Pipitone
  • 4,002
  • 4
  • 24
  • 39
  • I am absolutely sure I did commit. Beside, I would not be able to change to develop branch if I did not commit my changes on my branch. I did git add ., then git commit -m "my msg", on my branch, no conflicts and git status reported nothing wrong afterwards. I also ALWAYS do git status before doing any other command and I did it this time, so that is not issue 100%. In fact, I do it every single time before touching even terminal for multiple reasons: to see if all is clean and OK, to see what branch I am on etc. – cd491415 Nov 07 '18 at 23:19
  • to add more details, I attempted to solve the problem I described above by discrding all changs git merge did in 'develop' brnch. This allowed me to switch back to branch-A. But when I did that, now I see lots of files that have "deleted:" in front of their name. Again, I did not delete them, just by checking out branch-A, git did it and staged it automatically, so they now show as "Changes to be commited". In fact, our .gitignore file which was not changed by anyone for months (we got it from gitignore.io) is being marked as modified. Hope this gives bit more insights in what is going on – cd491415 Nov 07 '18 at 23:24
  • the files that git shows as modified this way include pretty much everything in project/repo. cs, png, axml, txt, xml, xaml, csproj, pfxappxmanifest, config, storyboard, plist, .ipa, .gitignore, probably pretty much everything. None of us has changed these for sure – cd491415 Nov 07 '18 at 23:36
  • ... and I just tried to unstage one of these files from SourceTree. And it would not unstage it. Something is definitely wrong, I wonder if my last 4 comments give you any more clue or could lead you to suggest some solution – cd491415 Nov 07 '18 at 23:38
  • ... But based on fact that also .png files get marked as modified, I dont think it is line-endings what is causing this issue. – cd491415 Nov 07 '18 at 23:59
  • 1
    My post explained how "I would not be able to change to develop branch if I did not commit my changes on my branch" isn't true. You can change branches, and the changes will simply follow you. What does `git diff` show? You say "changed". What exactly is being changed here? – Nicholas Pipitone Nov 08 '18 at 00:10
  • Is there something you would suggest doing to resolve this issue rather investigating it? I am thinking to somehow save my changes (dont know how yet), reinstall git and SourceTree, then reapply my changes on fresh clone (not sure how to do it yet either). From my reading, looks like git patch is meant for something like this? Thank you so much for your help :) – cd491415 Nov 08 '18 at 00:23
  • to your answer re switching branch, I tried again and I was able to switch even though I had uncommitted changes. Switching back to the branch that got auto-created changes by git, shows the changed files, all having D in front. git diff shows nothing and git status shows "deleted:" in front of file name. All are staged (png, gitignore, cs, csproj, .. pretty much all). When I click on file in SourceTree, it shows entire content as changed in the file which makes sense if they are marked as deleted. Trying to unstage a file in SourceTree does not unstage it, it stays as staged – cd491415 Nov 08 '18 at 00:35
  • I think this could be caused by line endings. Although I see non-textual files being affected such as png files (deleted, unstaged, staged or untracked), I read somewhere that these will be affected by line endings even though they are non-textual. – cd491415 Nov 08 '18 at 15:55
  • @would you be able to comment on this? https://stackoverflow.com/questions/50335447/git-says-there-are-changes-but-there-are-none I think I found few other issues that may give you some hints. Much appreciated again – cd491415 Nov 08 '18 at 23:26