简体   繁体   English

git reflog。 这是适当的用途吗?

[英]git reflog. Is this an appropriate use?

this is hypothetical at the moment, but it's a workflow I would like to put into practice. 目前这只是假设,但这是我要付诸实践的工作流程。

I have a template that I start all of my web projects from. 我有一个模板,可以从中启动所有Web项目。 I am currently using github to store the master template, and simply cloning each time I build a project. 我目前正在使用github来存储主模板,并在每次构建项目时都进行克隆。

The problem is that as I do more and more projects, I had features that would be useful in the template, but it is tricky put them in using my current workflow. 问题在于,随着我做越来越多的项目,我在模板中会有一些有用的功能,但是使用当前的工作流程却很难。

What I propose is that I pull the template from github at the start of each project, and build the project along a local branch. 我建议在每个项目的开始时从github提取模板,然后沿着本地分支构建该项目。 When I come across something that I think will be useful in the master template, I switch to the master branch, implement the changes there, submit to github and then use reflog to bring those changes with me to the current, local project state. 当我遇到我认为对master模板有用的东西时,我切换到master分支,在那里进行更改,提交给github,然后使用reflog将这些更改带到当前的本地项目状态。

Does this make any sense, and have I (as is likely) totally missed the point of reflog? 这有意义吗?我(很可能)完全错过了reflog的观点吗?

many thanks 非常感谢

In my opinion, reflog is one of the ugliest tools in git -- I wouldn't use it unless I had accidentally clobbered one of my own changes and had no other way to get at it. 我认为reflog是git中最丑陋的工具之一-除非我不小心破坏了自己的更改之一并且没有其他方法可以使用它,否则我不会使用它。

Given your proposed workflow, I would suggest doing all your coding in the local branch, and if you end up coding something useful for the template, just switch to master and cherry-pick the individual commits you'd like to pull in. 考虑到您建议的工作流程,我建议您在本地分支中进行所有编码,如果最终对模板有用的东西进行编码,则只需切换到master并挑选想要插入的单个提交即可。

http://www.kernel.org/pub/software/scm/git/docs/git-cherry-pick.html http://www.kernel.org/pub/software/scm/git/docs/git-cherry-pick.html

Simply said, this will rewrite the history. 简而言之,这将重写历史。 This will cause you pain if you work with github. 如果您使用github,这将使您感到痛苦。 As said before, reflog is not a tool that you'd use on a regular basis. 如前所述,reflog不是您经常使用的工具。

In your case, there is absolutely no reason to use reflog. 就您而言,绝对没有理由使用reflog。 You can have the same workflow just doing this. 您可以具有相同的工作流程。 Imagine that you are working on the my_local_project branch and you have some change that you want to make to the template. 假设您正在使用my_local_project分支,并且要对模板进行一些更改。 Then you just do: 然后,您只需执行以下操作:

git checkout master
# Hackety, hackety, make the change in your template
git checkout my_local_project
git merge master

Now all the changes that you made to the master branch will have been merged into my_local_project in a clean manner. 现在,您对master分支所做的所有更改都my_local_project干净的方式合并到my_local_project中。

This will even work (with just slight modifications) if you keep your projects in different repositories from the template. 如果您将项目保留在模板的不同存储库中,则甚至可以工作(只需稍作修改)。

I honestly still have no idea what you mean by "use reflog to bring those changes with me to the current, local project state". 老实说,我仍然不知道您的意思是“使用reflog将这些更改带到当前的本地项目状态”。 The reflog just displays past positions of a given ref. 引用日志仅显示给定引用的过去位置。 You still have to merge/rebase/cherry-pick to actually "bring" those changes anywhere else. 您仍然必须合并/变基/选择樱桃,才能将这些更改实际“带”到其他任何地方。 Generally merging is the most elegant way. 通常,合并是最优雅的方式。

For example: 例如:

git clone template local-project
cd local-project
git remote rename origin template-origin
# make changes and commit them
git add ...; git commit

# suppose changes have been made in the template (work as normal there)
# back in local-project, merge the template's master branch:
git pull template master

Nothing complicated at all. 一点都不复杂。 Just merge the branch with the changes you want. 只需将分支与所需的更改合并即可。 This is probably obvious, but make sure you never pull the other way - from the local project into the template. 这可能很明显,但是请确保您绝不会采用其他方法-从本地项目拖入模板。

And of course, mess with your remotes as appropriate. 当然,请根据需要与您的遥控器配合使用。 You'll probably want to create a new "origin" for local-project , pointing to its central (eg github-hosted) repository, and the same for template . 您可能要为local-project创建一个新的“源”,指向它的中央(例如github托管)存储库,并为template相同。 You could also point the template remote in local-project to the central template repository instead of your local clone of it, if you like. 如果愿意,您还可以将local-project中的远程模板指向中央模板存储库,而不是本地的本地克隆。

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

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