简体   繁体   English

Git:不要在Windows上更新某些文件

[英]Git: don't update certain files on Windows

We work with a git respository that has over 20,000 files. 我们使用的git仓库有20,000多个文件。

My group maintains local versions of about 100 or so of configuration and source files from this repository. 我的小组维护该存储库中大约100个左右的配置和源文件的本地版本。 THe original acts as a sort of base that several groups modify and tweak to their own needs (some core things are not allowed to be changed, but front end and some custom DB stuff are different between groups) 原始内容是一种基础,多个小组可以根据自己的需要进行修改和调整(不允许更改某些核心内容,但是各个小组之间的前端和某些自定义DB内容有所不同)

So we want to update to the latest version generally, but not have the git update overwrite the files that we keep local modifications for. 因此,我们通常希望更新到最新版本,但不要让git update覆盖我们保留本地修改的文件。

The machines we use are windows based. 我们使用的机器是基于Windows的。 Currently the repository gets cloned to a windows server that then gets checked out/cloned to the development machines (which are also windows). 当前,存储库被克隆到Windows服务器,然后被检出/克隆到开发机器(也是Windows)。 The developers make changes as necessary and recommit to our local repo. 开发人员根据需要进行更改,然后重新提交给我们的本地仓库。 The local repo updates against the master daily. 本地仓库每天都会针对主仓库进行更新。 We never commit back to the master. 我们从不退回主人。

So we want all the files that haven't been changed by our group to update, but any that have been changed (ever) won't get updated. 因此,我们希望所有未由我们小组更改的文件都进行更新,但是任何(曾经)更改的文件都不会更新。

Is there a way to allow this to happen automatically, so the windows server just automatically updates daily, ignoring those files we keep modifications for. 有没有一种方法可以使这种情况自动发生,因此Windows Server只是每天自动更新,而忽略了我们对其进行修改的文件。 And if we want to add a new file to this "don't update" list its just a right-click (or even a flat file list away). 而且,如果我们要向此“不更新”列表中添加新文件,只需单击鼠标右键(甚至是平面文件列表即可)。 I looked at git-ignore but it seems to be for committing, not for updating. 我看着git-ignore,但这似乎是为了提交,而不是为了更新。

Even better would be a way to automatically download the vanilla files but have them renamed automatically. 更好的方法是自动下载香草文件,但将其自动重命名。 For example settings.conf is a file we want to keep changes on generally, but if they modify the way entries in that file are handled or add extra options it would be nice it it downloaded it as settings.conf.vanilla or something so we just run a diff on .vanilla files against ours and see what we want to keep. 例如settings.conf是一个我们通常希望保持更改的文件,但是如果它们修改了该文件中条目的处理方式或添加了其他选项,那么最好将其下载为settings.conf.vanilla或其他内容,只需对我们的.vanilla文件进行比较,看看我们要保留什么。 Though this feature is not absolutely necessary and seems unlikely. 尽管此功能并非绝对必要,而且似乎不太可能。

If this cannot be accomplished on a windows machine (the software for windows doesn't support such features), please list some Linux options as well if available. 如果无法在Windows机器上完成此操作(用于Windows的软件不支持此类功能),请列出一些Linux选项(如果有)。 We do have an option to use a Linux server for hosting the local git repo if needed. 如果需要,我们确实可以选择使用Linux服务器来托管本地git repo。

Thanks. 谢谢。

It sounds like you're working with a third party code base that's under active development and you have your own customisations which you need to apply. 听起来您正在使用正在积极开发的第三方代码库,并且您需要应用自己的定制。

I think the answer you're looking for is rebase . 我认为您正在寻找的答案是rebase You shouldn't need to write any external logic to achieve this, except for a job which regularly pulls in the third party changes and rebases your modifications on top of them. 您不需要编写任何外部逻辑来实现此目的,除了一项工作需要定期提取第三方更改并在这些更改基础上重新进行修改之外。

This should also be more correct than simply ignoring the files you've modified, as you won't then accidentally ignore changes that the third party has made to those files (you may sometimes get a conflict, which could be frustrating, but better than silently missing an important change). 这也比不理会修改过的文件更正确,因为这样您就不会意外忽略第三方对这些文件所做的更改(您有时可能会遇到冲突,这可能会令人沮丧,但比默默地错过了重要的更改)。

Assuming that your local repo is indeed simply a fork, maintain your changes on your own branch, and every time you update the remote repository, simply rebase your local branch on top of those changes: 假设您的本地存储库确实只是一个分支,请在自己的分支上维护您的更改,并且每次更新远程存储库时,只需在这些更改之上重新构建您的本地分支即可:

git pull origin master
git checkout custom_branch
git rebase master

Edit 编辑

After you've done this, you'll end up with all the changes you made on your custom_branch sitting on top of master . 你这样做之后,你会用你对你所做的所有更改最终custom_branch坐在上面master You can then continue to make your customisations on your own branch, and development of the third party code can continue independently. 然后,您可以继续在自己的分支上进行自定义,并且第三方代码的开发可以独立地继续。

The next time you want to pull in the extra changes, you'll repeat the process: 下次您要进行其他更改时,将重复该过程:

Make sure you're on the master branch before pulling in changes to the third party code: 在对第三方代码进行更改之前,请确保您位于master分支上:

git checkout master

Pull in the changes: 引入更改:

git pull origin master

Change to your customised branch: 转到您的自定义分支:

git checkout custom_branch

Move your changes on top of the third party changes: 将您的更改移至第三方更改之上:

git rebase master

This will then put all your own changes on top of master again. 然后,这会将您自己的所有更改再次置于 master 之上 master itself won't be changed. master本身不会改变。

Remember that the structure of your repo just comes from a whole set of "hashes" which form a tree. 请记住,您的存储库的结构只是来自形成一棵树的整套“哈希”。 Your branches are just like "post it" notes which are attached to a particular hash, and can be moved to another hash as your branch grows. 您的分支就像附加在特定哈希上的“张贴”便笺一样,并且随着分支的增长可以移动到另一个哈希中。

The rebase is like chopping off a branch and re-attaching it somewhere else. rebase就像砍了分公司,并重新连接到其他地方。 In this case, you're saying something like "chop off our changes and re-attach them on top of the main trunk". 在这种情况下,您说的是“切断我们的更改并将其重新连接到主干顶部”。

If you can install a visual tool like GitX, it will really help to see how the branch tags move around when you rebase. 如果您可以安装GitX之类的可视工具,那么在重新设置基准时,将真正有助于查看分支标签如何移动。 The command line is ideal for working with but I find something like GitX is invaluable for getting a handle on the structure of your repo. 命令行是使用它的理想选择,但是我发现GitX之类的东西对于了解您的仓库结构非常有价值。

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

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