开发者

git : Small project work

开发者 https://www.devze.com 2023-01-29 08:40 出处:网络
I\'m currently trying to follow the small project based work-group mentioned in the Pro Git book : http://progit.org/book/ch5-2.html

I'm currently trying to follow the small project based work-group mentioned in the Pro Git book : http://progit.org/book/ch5-2.html

So, here's my set-up:

[Live Website Folder] 
|             |
|             |
Developer1    Developer2

The way that I achieved that was I did the following:

  1. git init --shared=0777
  2. git clone /live/website developer1
  3. git clone /live/website developer2

I was able to successfully clone my proj开发者_如何学运维ect and I went into developer1 folder. Here I make changes to my file index.html. Once, I make these changes, I do:

git add index.html
git commit -m 'Modified index.html --developer1'
git push

Now when I go to my /live/website directory and do a git status, it correctly tells me that the file index.html is modified. When I do:

git add index.html
git commit -m 'Modified index.html by developer1' 

It successfully makes the commit, but when I try to vi index.html, the file that I see is the original/un-modified one. I don't see the changes made by developer1, within that file. Is this expected behavior?


What git status is telling you is that index.html is different to what is in the git index.

After you push, your /live/website repo contains the updated index.html in the index, but the old index.html in the working copy. You need to do git reset --hard HEAD followed by git checkout -f inside /live/website to reset the working copy to the same as the HEAD commit.

I'd suggest that you modify your setup slightly. Add a staging repository that is bare and push changes into that. Add a post-update hook that runs git pull staging master inside /live/website. This will ensure that the live website gets updated as soon as a commit is pushed in.

In glorious ascii art:

 /live/website
       |
       |
/path/to/staging (bare)
  |          |
  |          |
dev1        dev2

EDIT: Updated to correct command sequence for fixing the working copy.


It looks like you are pushing into a non-bare repository. This is not recommended and can have unexpected effects to trap the unwary. Instead, you might want to create a new, bare repository to serve as the main repository.

mkdir /git/project.git
cd /git/project.git
git init --bare --shared
cd /live/website
git remote add origin /git/project.git
git push origin master

Then, developer1 and developer2 should clone from /git/project.git, and push there too. When you want to update your live website:

cd /live/website
git pull


When you push to another directory it does not update the checkout of that remote directory.

You would have to do (on live/website):

git reset --hard

to get the new updates from developers.

This happens because your tree is currently pointing to a previous commit tree. but when doing 'git status' it fetches the most recent changes from the branch you are on.

One way to get out of this is to set up a git-hook on post-receive

0

精彩评论

暂无评论...
验证码 换一张
取 消