git 新手——如何将克隆存储库中的更改更改为原始存储库?
这可能是一个相当新的问题,但我似乎无法弄清楚。
这就是我所做的...
在服务器上(通过 ssh):
- 在专用服务器上创建了一个站点
- 在那里创建了一个 git 存储库(我认为是 git init?)
- 添加并提交了所有内容
在我的办公室:
- 克隆我的开发机器上的存储库
- 提取了所有内容
- 对本地文件进行了一些更改
- 再次添加了文件(这是对的吗?不像 svn!)
- 进行了提交
- 进行了推送
...现在,在服务器上,如果我执行 git show
,它显示了一个差异,其中服务器的最后一个内容副本已被删除,而我从办公室推送的内容正在被添加。这就是我想要发生的事情。我不明白的是:我需要在服务器上做什么才能使我从办公室推送的更改变得“实时”?
我在使用 svn 部署网站方面取得了相当大的成功在过去,我想我也可以用 git 摆脱它......但显然我错过了一些难题。感谢您的任何帮助。
编辑 - 我刚刚注意到这篇文章:Git - 将更改从克隆拉回到主服务器
我应该将我的办公室存储库拉到我的服务器上而不是把它放在那里吗?那么,从办公室 ssh 进入服务器,然后使用 git+ssh 返回办公室来拉取该存储库?这看起来有点疯狂,如果可能的话,我宁愿弄清楚如何让推送顺利进行。
重新表述问题
我真的只想应用git show
显示的补丁。 git 有内置的方法吗?
answer
看起来服务器上的 git checkout -f
做了我想要的事情,但是创建一个 --bare 存储库将是一个更好的方法(我已经改变了现在就到此设置)。
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):
- Created a site on a dedicated server
- Created a git repo there (
git init
I think?) - Added and committed everything
At my office:
- Cloned the repo on my development machine
- Pulled everything
- Made some changes to local files
- Added the files again (is this right? not like svn!)
- Did a commit
- Did a push
...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. 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. Thanks for any help.
edit - I just noticed this post: Git - pulling changes from clone back onto the master
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? 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
. Does git have a built-in way of doing that?
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常在服务器上,您会执行 git init --bare 来创建一个没有工作目录的存储库。如果这是您采取的路线,那么您必须将更改从那里拉到 Web 目录作为“部署”步骤。因此,您的工作流程可能类似于...
此时,您的任何更改在您的网站上都不可见。您需要“部署”它们。
5. 将最新更改从服务器上的中央存储库拉取到 Web 上提供的 Web 服务器文件夹。
git 教程 非常好,就像“Pro Git",一本免费的在线书籍
Usually on the server you would do a
git init --bare
which creates a repo with no working directory. 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. So your work flow might look like...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.
There git tutorials are very good as is "Pro Git", a free online book
如果您推送到的服务器上的 git 存储库用于实时系统,您可能需要执行 [编辑]
git reset [--hard|...] HEAD(请参阅 git-reset 手册页有关是否使用
--hard
或其他内容的详细信息重置服务器上的所有未提交的修改)。如果实时系统位于服务器上的其他位置,请从您推送到的存储库(在实时系统的目录中)执行 git pull 。
push 和 fetch 是互补的,即从 A 推送到 B 就像从 B 获取 A 一样。
拉是获取,然后是结账。
编辑:
您还应该阅读jmohr链接到的文章,了解push和之间的细微差别>获取 / 拉取:git Push 不将更改发送到远程 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).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).push and fetch are complementary, i.e. pushing from A to B is like fetching A from B.
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