Search code examples
gitcloud9-ide

Unable to commit to gitbucket from cloud9 because of .c9 files


commit your changes or stash them before you can switch branches.

error: The following untracked working tree files would be removed by checkout:
.c9/metadata/tab1
.c9/metadata/tab11
.c9/metadata/tab12
.c9/metadata/tab17
.c9/metadata/tab18
.c9/metadata/tab23
.c9/metadata/tab24
.c9/metadata/tab25
.c9/metadata/tab26
.c9/metadata/tab27
.c9/metadata/tab28
.c9/metadata/tab29
.c9/metadata/tab30
.c9/metadata/tab31
.c9/metadata/tab33
.c9/metadata/tab5
.c9/metadata/tab6
.c9/metadata/tab8
.c9/metadata/tab9
.c9/metadata/workspace/README.md
.c9/metadata/workspace/app/controllers/application_controller.rb
.c9/metadata/workspace/app/controllers/candy_pages_controller.rb
.c9/metadata/workspace/app/views/candy_pages/butterfinger.html.erb
.c9/metadata/workspace/app/views/candy_pages/home.html.erb
.c9/metadata/workspace/app/views/candy_pages/reeses.html.erb
.c9/metadata/workspace/app/views/candy_pages/skittles.html.erb
.c9/metadata/workspace/app/views/candy_pages/snickers.html.erb
.c9/metadata/workspace/app/views/layouts/application.html.erb
.c9/metadata/workspace/config/routes.rb
.c9/metadata/workspace/test/controllers/candy_pages_controller_test.rb

How do I get rid of these? I've added

#Ignore all .c9 specific files
/.c9/

to my .gitignore, but that doesn't help what's already been tracked by git.

I've done a

$ git rm --cached .c9/ -r

but when I try to get back to my master

$ git checkout master

I'm unable to proceed because of the untracked working tree files...can someone help me with this?


Solution

  • The issue I think is, you have these files already committed in some of your earlier commits and these are part of master now.

    If that is the case, doing a git log .c9/ will show you the commits as well. To work around this, just delete the files manually once, using rm -rf .c9/. In case you want to keep those files around, rename the .c9 folder as something else (mv .c9 .c9.bkp). If you now do a git status, there are two possibilities, either there are no more files shown within the .c9 directory, or there are some files which are coming as modified. In the latter case, do a git checkout .c9 to re-generate only those files which are being tracked by git.

    Now do a git pull origin master, to pull the latest master branch. Once the changes are pulled in, do

    git rm -r --cached .c9/
    echo ".c9*" >> .gitignore
    git add .gitignore && git commit -m "Removing .c9 metadata files"
    

    And now, push these changes back to the master branch using

    git push origin master
    

    When working on any other branch, rebase them master first (using git rebase origin/master) so that any .c9 files committed in another branch doesn't creep back into master.

    Now, you can restore your .c9 folder from the backup we made if needed using mv .c9.bkp .c9.