简体   繁体   English

git的新手-如何将克隆的回购更改为原始回购?

[英]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):

  • Created a site on a dedicated server 在专用服务器上创建站点
  • Created a git repo there ( git init I think?) 在那里创建了一个git repo(我认为是git init吗?)
  • 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!) 再次添加文件(对吗?不像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. ...现在,在服务器上,如果我执行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
  1. Clones server repo to your dev machine, which you've already done 将克隆服务器存储库复制到您的开发机器上
  2. Commits the bug fix to your local repo...not the server's repo 将错误修复提交到本地存储库...而不是服务器的存储库
  3. Commits the new feature to your local repo...again, not the server's 再次将新功能提交给本地存储库,而不是服务器的
  4. Pushes all changes from your master branch to the server's master branch 将所有更改从您的master分支推送到服务器的master分支

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链接的有关pushfetch / pull之间的细微差别的文章: git push不会将更改发送到远程git存储库

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用原始项目的更改更新本地克隆的 git repo(没有 fork!) - how to update locally cloned git repo with changes from the original project (no fork!) GIT 提交到克隆的仓库(带有新的远程)和原始仓库 - GIT commit both to cloned repo (with new remote) and to the original repo 克隆了一个 repo,如何从原始 repo 更新新 repo 中的所有分支/master? - Cloned a repo, how to update all branches/master in new repo from original repo? 我从 git 存储库中的不同分支克隆,进行了更改,并希望推送到存储库中的分支。 如何? - I cloned from a different branch in my git repo, made changes, and want to push to my branch in the repo. How? 如何从git克隆存储库,但仍获得对原始存储库的更新? - How do I clone a repository from git but still get updates made to the original repo? 如何推送我从 github 克隆的存储库并对我的 github 存储库进行更改? - How do I push the repository I cloned from github and made changes to it to my github repo? 如果还没有与我的本地存储库链接的远程存储库,我如何 go 到克隆的存储库并签入 git bash? - How do I go to the cloned repo and check in git bash if there isn't already a remote repo linked with my local repo? git-subtree:从克隆的repo中推送更改 - git-subtree: Push changes from an cloned repo 如何在不使用原始仓库的情况下删除通过git-new-workdir创建的工作副本? - How do I remove a working copy created via git-new-workdir without hosing the original repo? 与Git混淆。 我应该将我的更改推送到我克隆的仓库吗? - Confusion with Git. Should I push my changes to the repo from where I had cloned?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM