简体   繁体   English

如何将github与本地存储库同步?

[英]How can I synchronize github with a local repository?

I didn't find a clear answer to this one (many things are overwhelming to newbies at git): 我没有找到一个明确的答案(很多事情对git的新手来说是压倒性的):

I have a local repo and a remote at github consisting of files: A, B and C. 我在github上有一个本地仓库和一个远程文件夹,其中包含文件:A,B和C。

  • This morning I changed local file A. 今天早上,我更改了本地文件A。
  • At noon, remote B was changed. 中午,远程B被更改。
  • Later on, I decided to change some comments at local file C and some code at remote C. 后来,我决定更改本地文件C的一些注释 远程 C的一些代码。

My draw depicts the files and their changes: 我的绘图描述了文件及其更改:

local       remote
 A  ------->   A
 B  <-------   B
 C  <------>   C    

In the evening, I'm just staring the repos. 晚上,我只是盯着仓库。 Is there any chance to finish promptly? 有没有机会立即完成? Anyone? 任何人?

Commit all of your local changes first. 首先提交所有本地更改。 Make sure your working directory is clean: 确保您的工作目录是干净的:

$ git status

should return: nothing to commit, working directory clean 应该返回: nothing to commit, working directory clean

Then, pull in the remote's changes: 然后,拉入遥控器的更改:

$ git pull remote-name branch-name
# it's probably git pull origin master

Then push your changes to share with the remote: 然后推送您的更改以与远程共享​​:

$ git push origin master

My local workfolw allows your to untie the pull and push stages properly, and it is the following: 我的本地工作流程可让您正确解开推拉阶段,具体步骤如下:

  1. Store your local uncommitted changes with git stash : 使用git stash本地未提交的更改:

     git stash 
  2. Update your local repo with remote version one: 使用远程版本1更新本地存储库:

     git pull 

    So you get: 这样就得到:

     local remote B <------- B C <------- C 
  3. Apply local changes, and merge all inconsistiences, fix the files if any require, and add them into index, and commit merge: 应用本地更改,合并所有不一致之处,如有需要,修复文件,然后将其添加到索引中,然后提交合并:

     git stash pop vim ... git add . git commit 
  4. Edit file C , and commit it. 编辑文件C ,然后提交。

     vim C git add C git commit 
  5. Push changes into remove repo: 将更改推送到删除存储库中:

     git push 

    So you'll get: 这样您将获得:

     local remote A -------> B C -------> C 

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

相关问题 如何将本地存储库与GitHub上的中央存储库同步? - How can I synchronize my local repositories with the central one on GitHub? GIT:将本地文件同步到新的github存储库 - GIT: Synchronize local files to new github repository 我如何忽略一些文件到与 github 同步的本地存储库? - How can i ignore some files into a local repository synched with github? 如何同步GitHub存储库和多个Gists - How to synchronize a GitHub repository and multiple Gists 如何使用 git 与无法连接到 github 的服务器同步? - How can I use git to synchronize with a server that cannot connect to github? 无法从本地存储库推送到 github 存储库 - Can not Push to github repository form local repository 我可以将我的本地 Github 存储库与 WAMP localhost 文件夹结合起来吗? - Can I combine my local Github repository with WAMP localhost folder? 如何将我的本地 git 存储库恢复到它在 GitHub 上的 state? - How can I revert my local git repository to the state it has on GitHub? 我怎样才能让多个项目在一个 GitHub 存储库中拥有自己的本地 git 存储库? - How can I have multiple projects with their own local git repositories in one GitHub repository? 使用 GitHub,如何将我的本地存储库恢复到上次推送到源之前的状态? - Using GitHub, how can I restore my local repository to the state it was in before my last push to the origin?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM