[英]New to git — how do I get changes from cloned repo into original repo?
This is probably quite a newb question, but I can't seem to figure it out. 这可能是一个很新的问题,但是我似乎无法弄清楚。
Here's what I did... 这是我做的...
On the server (via ssh): 在服务器上(通过ssh):
git init
I think?) git init
吗?) At my office: 在我的办公室:
...now, on the server, if I do git show
, it shows a diff where the server's last copy of stuff is removed and the stuff I pushed from my office is being added. ...现在,在服务器上,如果我执行
git show
,它会显示一个差异,其中删除了服务器上的内容副本,并添加了我从办公室推送的内容。 That's what I want to happen. 那就是我想发生的事情。 What I can't figure out is: what do I need to do on the server to make the changes I pushed from my office become "live?"
我不知道的是: 我需要在服务器上做什么才能使从办公室推送的更改变为“实时”?
I've had pretty good success deploying websites with svn in the past, and I figure I can get away with it with git too... but obviously I'm missing some piece of the puzzle. 我过去在使用svn部署网站方面取得了相当不错的成功,而且我认为我也可以通过git来摆脱它……但是显然我错过了一些难题。 Thanks for any help.
谢谢你的帮助。
edit - I just noticed this post: Git - pulling changes from clone back onto the master 编辑 -我刚刚注意到了这篇文章: Git-将更改从克隆复制回主服务器
Should I be pulling my office repo onto my server instead of pusing it there? 我应该将我的办公室存储库拉到服务器上而不是在服务器上使用它吗? So ssh from the office into the server and then have it git+ssh back into the office to pull that repo?
那么从办公室ssh到服务器,然后将git + ssh送回办公室以拉回该仓库吗? That seems kind of crazy, I'd rather figure out how to make the push go through if possible.
这似乎有点疯狂,我宁愿弄清楚如何尽可能地进行推动。
rephrasing the question 改写问题
I really just want to apply the patch shown by git show
. 我真的只想应用
git show
所示的补丁。 Does git have a built-in way of doing that? git有内置的方法吗?
answer 回答
It looks like git checkout -f
on the server did what I wanted, but creating a --bare repo would have been a better way to go (I've changed to this setup now). 看起来服务器上的
git checkout -f
达到了我想要的目的,但是创建--bare仓库可能是更好的方法(我现在更改为此设置)。
Usually on the server you would do a git init --bare
which creates a repo with no working directory. 通常在服务器上,您需要执行
git init --bare
来创建没有工作目录的存储库。 If that is the route you took then you would have to pull the changes from there to the web directory as the "deployment" step. 如果那是您采取的途径,那么您将必须将更改从那里拉到Web目录,作为“部署”步骤。 So your work flow might look like...
因此您的工作流程可能看起来像...
On dev PC:
1. git clone <path to server repo>
*make code changes*
2. git commit -am "fixed a bug"
*add some new feature*
3. git commit -am "added cool new feature"
4. git push origin master
On the server:
*cd to www folder*
5. git pull
At this point, none of your changes are visible on your website. 此时,您所做的任何更改都不会显示在您的网站上。 You would need to "deploy" them.
您将需要“部署”它们。
5.Pulls the latest changes from the central repo on the server to the web server's folder(s) that are being served up on the web. 5.将最新更改从服务器上的中央存储库拉到Web上正在提供的Web服务器的文件夹。
There git tutorials are very good as is " Pro Git ", a free online book 那里的git教程和免费的在线书“ Pro Git ”都非常好
If the git repo on the server you pushed to is for the live system, you would probably have to do a [ EDIT ] git reset [--hard|...] HEAD
on the server after a push I guess (see git-reset man page for details on whether using --hard
or something else; --hard
resets all non-committed modifications on your server). 如果您推送到服务器上的git repo是针对实时系统的,那么我想在推送之后您可能必须在服务器上执行[ EDIT ]
git reset [--hard|...] HEAD
(请参阅git-重置手册页以获取有关使用--hard
还是其他方法的详细信息; --hard
重置服务器上所有未提交的修改)。
If the live system is somewhere else on the server, do a git pull
from your repo you pushed to (in the directory with your live system). 如果实时系统在服务器上的其他位置,请从推送到的存储库中进行
git pull
(在实时系统的目录中)。
push and fetch are complementary, ie pushing from A to B is like fetching A from B. 推和取是互补的,即从A推到B就像从B取A。
pull is a fetch followed by a checkout . 拉是先取后结帐 。
EDIT: 编辑:
You should also read the article linked to by jmohr on the subtle differences between push and fetch / pull : git push not send changes to remote git repository 您还应该阅读jmohr链接的有关push和fetch / pull之间的细微差别的文章: git push不会将更改发送到远程git存储库
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.