Can I use git to manage a website even if other people update it without using git?

随声附和 提交于 2019-12-21 20:19:28

问题


So let's say I got a web server that I can access over ftp. Most people update it using dreamweaver, and I update by basically copying and pasting manually between my computer and the server. My question is, can I use git to manage the site (and not have to manually copy/paste), while other people update it using other methods?

  • I can't install much on the server. I would like to only put files on the server to set this up.
  • I do not want to have to manually copy and paste to upload to the server.
  • I do not want to inadvertently undo the changes of others not using git, nor do I want to make them use git.
    • That said, if both me and others edit the website at the same time, I would want to take advantage of git's merging capabilities.

How should I set this up? (Also, what scripts could I put on my computer to make this easier (both hooks and non-hooks)? (I would know how to make them, I just would like tips as what kind I should make for this workflow.))

Note: I use linux, if that matters. (Also, I use git from the command line).

Note: I am fine with doing some stuff manually that normally isn't necessary (such as turning my teammates changes into commits). It is manual copying and pasting I want to avoid.


回答1:


What you can do, while not installing git on the server, is maintaining on your local machine a local copy rsync'ed of the server web site.
If your server supports sftp, you can use csync (without having to install it on the server side): it is better than rsync, and bidirectional.

Then you can have your own git repo, and whenever you want to add or compare changes from the website, you can switch branch, and do:

git --work-tree=/path/to/csync/folder status .

That compare your current repo index and that synchronized local folder which reflects the website.

You have two branches in your git repo, one for your current work and one for incorporating the website in the repo.

You can merge the two locally, and when you are ready, you checkout the repo using the csync'ed folder as a working tree

git --work-tree=/path/to/csync/folder checkout HEAD -- .



回答2:


  1. Somehow set up a method that you can run git commands (on your computer) that affects the FTP server, as well as being able to push to the FTP server (such as using rsync/csync, mounting the ftp server locally, or this combined with some initial copying and pasting).
  2. In the servers git repo, set receive.denyCurrentBranch to updateInstead, via the command git config receive.denyCurrentBranch "updateInstead". See Push to deploy.
  3. Now, when you push from your local repo the server, if the server has been modified, you will get an error like this
    ! [remote rejected] master -> master (Working directory has unstaged changes) error: failed to push some refs to '../remote'
    
    to resolve this, you must commit changes made by your teammates on the remote server. You may want to cherry-pick this. Then go to step 4.
  4. If the local server is in sync with its git branch, you simply push to it, the it's working tree will also be updated. (Keep in mind you still have to things like doing git pull before git push and such.)



回答3:


I use two servers on one website for this purporse. Production, with only FTP access and development with full access. I do pushing on development server, where I have post-receive script, which checkouts bare repo to temporary folder, and than calls Python script, which uploads code to FTP. I don't know a way to allow other people to use FTP. You should really tell them to use git, it'll be easier for everybody, and you will also have much better control of the code. If you have this setup, you can have only one branch to push to production server, and others will be just development.




回答4:


I have not done this to see how usable it would be, but you could mount the remote directory using for example curlftpfs. I'd expect this gives you a few alternatives to using it:

  1. Have it unmodified, containing only working files and have the repository (i.e. contents of .git) locally at directory specified by GIT_DIR environment variable. core.worktree should be configured to the ftp mount.
  2. You can have it as a true repository with .git subdirectory, do git init etc.
  3. Have in it a .git file instead of using the GIT_DIR environment variable.
  4. Have it manageable with git worktree, after some manual setup as currently there is no automatic conversion of an existing directory to a worktree.

Much depends on if you are the only git user or if there are others bothered with your private changes in the ftp directory.



来源:https://stackoverflow.com/questions/34695151/can-i-use-git-to-manage-a-website-even-if-other-people-update-it-without-using-g

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!