简体   繁体   中英

Why is git not pushing contents of a folder?

After copying a folder 'myapp' into to my working folder, I do the following to add it to my staging area:

git add .

and then commit the changes:

git commit

Then I push my changes to Heroku:

git push heroku master

So my folder, called 'myapp' is present on heroku, but the problem is that it's completely empty.

When I do the following,

git clone myapp myapp2

the folder clones properly on my local machine with all expected subcontents.

Does anyone know why the subfolders' contents are not being pushed to Heroku properly? What am I doing wrong?

To answer the questions below:

  1. I am doing the git add . in my top level folder (the folder that contains folder myapp ). Doing git status shows `no changes added to commit (use "git add" and/or "git commit -a")
  2. Yes, myapp contains files/folders (my django project)
  3. I deleted my .gitignore file because I placed my virtual environment in another place altogeher so it's no longer in my project folder so I don't think that's affecting it.

Ok, I seemed to have solved the problem. Somehow git got in a weird state. I don't really understand how, but for some reason it wasn't adding any of the files in the folder.

I simply copied that folder and gave it a new name, and then followed the exact same process I had been doing all along, and it finally uploaded properly.

By default, you cannot push changes to a checked-out branch of a repository. It usually causes major problems! Here is what usually happens:

$ git push heroku master
...error messages...
To heroku
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'heroku'

Since you haven't mentioned any error messages , I'm assuming that you've added the following to your heroku repository configuration, or you're running a fairly old version of Git:

[receive]
        denyCurrentBranch = false

It sounds like you want to check out a fresh copy of the master branch whenever you push a new version to your heroku repository. That can be achieved with a post-receive hook. Create a file in your heroku repository .git/hooks/post-receive , and give it +x permissions.

#!/bin/sh
while read oldrev newrev refname
do
    if test "$refname" = refs/heads/master
    then
        ( cd ..; GIT_DIR=.git; git reset --hard )
    fi
done

Now, whenever you push a new master branch to heroku , the hook will run and check out the new branch. There are better ways to do this kind of thing, but this is simple.

Summary: By default, when you push changes, it only changes the history but not the working tree . The assumption is that someone might be working on that tree, so doing anything to it could be destructive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM