Why .gitignore and .metadata are not getting commited?

251

The files probably don't exist in your working tree, but do exist on the remote

  • add the files explicitly git add .gitignore .metadata
  • stash 'em git stash
  • then merge git pull
  • unstash git stash pop

The problem with git add * is that * is expanded by your shell, but not including .dotfiles

Share:
251
PeakGen
Author by

PeakGen

CTO

Updated on December 31, 2022

Comments

  • PeakGen
    PeakGen over 1 year

    I am developing a flutter app, using bitbucket as the version control. Below is the .gitignore file:

    # Miscellaneous
    *.class
    *.log
    *.pyc
    *.swp
    .DS_Store
    .atom/
    .buildlog/
    .history
    .svn/
    
    # IntelliJ related
    *.iml
    *.ipr
    *.iws
    .idea/
    
    # The .vscode folder contains launch configuration and tasks you configure in
    # VS Code which you may wish to be included in version control, so this line
    # is commented out by default.
    #.vscode/
    
    # Flutter/Dart/Pub related
    **/doc/api/
    **/ios/Flutter/.last_build_id
    .dart_tool/
    .flutter-plugins
    .flutter-plugins-dependencies
    .packages
    .pub-cache/
    .pub/
    /build/
    
    # Web related
    lib/generated_plugin_registrant.dart
    
    # Symbolication related
    app.*.symbols
    
    # Obfuscation related
    app.*.map.json
    
    # Android Studio will place build artifacts here
    /android/app/debug
    /android/app/profile
    /android/app/release
    

    I do git add * and then git commit -m "message" to make the commit. How unfortunate , the .gitignore file never get commited.

    When I am trying to do git pull or git pull --rebase, I get the below error

    Updating 200df3e..02afe50
    error: The following untracked working tree files would be overwritten by merge:
            .gitignore
            .metadata
    Please move or remove them before you merge.
    Aborting
    

    Browsing the internet, the issue seems to be the .gitignore file and metadata not getting commited. So the pull can't merge them.

    How can I make sure these files are commited?

    UPDATE

    I followed user ti7's answer, after the command git stash pop, I got the below message. what does that mean?

    On branch master
    Your branch is up to date with 'origin/master'.
    
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git restore <file>..." to discard changes in working directory)
            modified:   ios/Flutter/Debug.xcconfig
            modified:   ios/Flutter/Release.xcconfig
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
            ios/Podfile
    
    no changes added to commit (use "git add" and/or "git commit -a")
    Dropped refs/stash@{0} (799d2e53c1509af435d5d4d589a0ded18d3aad64)
    
    • Jake Worth
      Jake Worth over 2 years
      It seems like you already have versions of these files on your remote. Can you confirm?
    • PeakGen
      PeakGen over 2 years
      @JakeWorth: Yes, thats right
  • PeakGen
    PeakGen over 2 years
    Thank you. Seems it worked. But after the last command I have another output. I made an update to my question, please check.
  • ti7
    ti7 over 2 years
    @JustCause git stash pop is just reporting git status and that it dropped the stash from its stack of stashes (git stash list would show you other stashed refs if you had any)
  • ti7
    ti7 over 2 years
    stashing will stash both staged changes (this is why you need to add the dotfiles) and also unstaged changes to your working tree (whatever else you were working on locally, which presumably you also want to merge) .. popping the stash will bring the whole changeset back on top of the new working HEAD (in you case probably fast-foward merging from remote with git pull, but this also works if you change branches, etc. which can be a convenient workflow!), so git status is displayed to help interpret what happened
  • PeakGen
    PeakGen over 2 years
    Thanks! I guess it is done then. The message it generated for is not an error right?
  • ti7
    ti7 over 2 years
    anytime! and not at all, rather it's a success (you could check the return code echo $?) to see what git thinks too! you're actually experiencing some flavor of the first example in the docs git-scm.com/docs/git-stash#Documentation/…