skip to Main Content

Background

I’m new to git, and I’m testing it as a version control for a website that is not hosted on github. I have made the public_html a git repo and created a bare repo outside the public_html that I push all the commits and tags to. My goal is to be able to tag changes I make to the website and have the option to quickly revert back to previous versions when desired. So far with my testing, I have been able to accomplish this by either using reset or checkout followed by the tag name to go back to previous versions.

The Problem

I encounter problems when I make new version tags that involve removing files from a previous tag. If I try to reset to or checkout the previous tag where the files were once present and functional, visit requests for these pages return "Internal server error". I know the files are there because I see them reappear in the public_html folder (as seen when refreshing cpanel, or filezilla). If I download these files, delete git from my website altogether, and add them back to the public_html folder, they work fine, indicating the files have not been modified or corrupted. Furthermore, when at a tag where the files are indeed removed, I get a "Page not found" result.

Is this a common issue? Any tips, advice, or workarounds would be much appreciated.

Update 1

Based on the kind suggestions of @VonC, I have tried

  1. Preventing unwanted EOL changes by setting the core.autocrlf to FALSE.
  2. Running git clean.

Unfortunately, these suggestions did not resolve the issue. I have also determined that this issue happens with PHP files but not HTML. I have continued reading up on my own, but I’ve not yet found any reports of a similar issue. I hope to figure this out soon. Currently, I would be unable to revert to a previous version if I ended up removing files and regretting it, which is essentially one of the primary benefits I hope to get from git.

Also, I was curious if git modifies permissions, but I’ve checked, and they’re unchanged.

Update 2

I thought it might be helpful if I specified everything I tried in case someone wants to attempt recreating the problem.

$git init --bare bare_repo.git
$cd public_html
$git init
$git remote add origin ../bare_repo.git
$git add index.html # simple testing only "hello world" 
$git add commit -m "index.html"
$git tag -a v001 -m "v001"
$git push origin master --tags

Now add in a PHP file:

$git add phpinfo.php # again for testing only, includes <?php  phpinfo(); ?>
$git add index.html  #file changed to include link to phpinfo.php
$git commit -m "phpinfo.php"
$git tag -a v002 -m "v002"
$git push origin master --tags

Now, checkout v001:

 $git checkout v001 

The index.html returns back to origin state without link, and phpinfo.php disappears from the public_html folder.

Now, checkout v002:

  $git checkout v002

The index.html regains link, and phpinfo.php re-appears in public_html.

However, when I try to go to phpinfo.php, I get the "Internal server error or misconfiguration" page load.

2

Answers


  1. Chosen as BEST ANSWER

    I found the problem had to do with GIT modifying permissions after checkout or reset operations. It changes the files from 664 to 644, which enables group writing. Although I had considered permission changes I had missed that this was happening. This happens with both HTML and PHP files, but it only manifested as a problem for PHP files. A quick search suggests solutions exist for this problem, so its just an issue of picking the best approach. Thanks @VonC for taking the time to consider my issue.


  2. Try a stricter way to reset or checkout:

    git reset --hard anOldTag
    git clean -fd
    

    Adding git clean would hep make sure the resulting working tree only include files from the SHA1 (here a tag) reset or checked out.
    Be sure to test it out forst in a separate site, in order to validate it does not remote too much file!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search