简体   繁体   English

Github:合并 github 存储库时保持本地文件不变

[英]Github: Keep a local file un-changed when merging github repositories

I have access to a public repository that is frequently updated.我可以访问经常更新的公共存储库。 On my local merged repository, I have to make some changes to some specific files in order to meet my requirements.在我的本地合并存储库中,我必须对某些特定文件进行一些更改以满足我的要求。

My problem is, every time I make a pull of the original repository, my local changed files are also lost.我的问题是,每次拉取原始存储库时,我的本地更改文件也会丢失。

How can I keep my local repository updated and do not allow my "local changed files" to be updated?如何保持我的本地存储库更新并且不允许我的“本地更改的文件”被更新?

Basically I need to get the new files that have been changed only at remote repository and not the one changed on my side.基本上,我需要获取仅在远程存储库中更改的新文件,而不是在我这边更改的文件。

UPDATED: The proposed solution ( Git Pull While Ignoring Local Changes? ) is different from my actual requirement, since the user from the linked post wants to git pull the full repository and "override" any local changes he made.更新:建议的解决方案( Git Pull While Ignoring Local Changes? )与我的实际要求不同,因为来自链接帖子的用户想要 git pull 完整存储库并“覆盖”他所做的任何本地更改。 In my case, I want to define some files changed locally to not be changed by the git pull.就我而言,我想定义一些在本地更改的文件,以免被 git pull 更改。

I want to keep some files changed locally unchanged and git pull the remaining repository我想保持一些本地更改的文件不变,并 git pull 剩余的存储库

A way to do this cleanly would be to use git-rebase.一种干净地做到这一点的方法是使用 git-rebase。

Essentially you would reset your local repo to the (updated) version of the remote public repo and then apply your changes again on top.本质上,您会将本地存储库重置为远程公共存储库的(更新)版本,然后再次应用您的更改。 This way your changes will always be on top of a copy of master from the remote repo.这样,您的更改将始终位于远程存储库中的master副本之上。

Assuming you have a repo with your changes on top currently, the workflow would look like this:假设您当前有一个包含更改的存储库,工作流程将如下所示:

git fetch
git rebase origin/master
... [fixup any conflicts you see when trying to reapply your changes]

See a description of rebase for more details.有关更多详细信息,请参阅rebase的描述。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM