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

发布于 2024-10-27 11:16:09 字数 336 浏览 5 评论 0原文

目前这是假设的,但这是我想付诸实践的工作流程。

我有一个模板,我可以从该模板开始我的所有网络项目。我目前使用 github 来存储主模板,并在每次构建项目时简单地克隆。

问题是,随着我做越来越多的项目,我拥有在模板中有用的功能,但使用我当前的工作流程来使用它们是很棘手的。

我的建议是在每个项目开始时从 github 中提取模板,并沿着本地分支构建项目。当我遇到一些我认为在主模板中有用的东西时,我会切换到主分支,在那里实现更改,提交到 github,然后使用 reflog 将这些更改带到当前的本地项目状态。

这有任何意义吗?我(很可能)完全错过了转发日志的意义吗?

非常感谢

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. I am currently using github to store the master template, and simply cloning each time I build a project.

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. 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.

Does this make any sense, and have I (as is likely) totally missed the point of reflog?

many thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你的往事 2024-11-03 11:16:09

在我看来,reflog 是 git 中最丑陋的工具之一——我不会使用它,除非我不小心破坏了自己的一项更改并且没有其他方法来获取它。

鉴于您提出的工作流程,我建议在本地分支中进行所有编码,如果您最终编码了对模板有用的内容,只需切换到 master 并挑选您想要拉入的各个提交即可。

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

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.

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.

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

友欢 2024-11-03 11:16:09

简单地说,这将改写历史。如果您使用 github,这将会给您带来痛苦。如前所述,reflog 不是您经常使用的工具。

就您而言,绝对没有理由使用 reflog。您只需执行此操作即可拥有相同的工作流程。想象一下,您正在 my_local_project 分支上工作,并且您想要对模板进行一些更改。然后您只需执行以下操作:

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

现在您对 master 分支所做的所有更改都将以干净的方式合并到 my_local_project 中。

如果您将项目保存在与模板不同的存储库中,这甚至可以工作(只需稍加修改)。

Simply said, this will rewrite the history. This will cause you pain if you work with github. As said before, reflog is not a tool that you'd use on a regular basis.

In your case, there is absolutely no reason to use 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. 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.

This will even work (with just slight modifications) if you keep your projects in different repositories from the template.

帅气称霸 2024-11-03 11:16:09

老实说,我仍然不知道“使用 reflog 将这些更改带到当前的本地项目状态”是什么意思。引用日志仅显示给定引用的过去位置。您仍然需要合并/变基/择优挑选才能真正将这些更改“带到”其他地方。一般来说合并是最优雅的方式。

例如:

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

一点也不复杂。只需将分支与您想要的更改合并即可。这可能是显而易见的,但请确保您永远不会以其他方式拉取 - 从本地项目到模板中。

当然,适当地调整你的遥控器。您可能希望为 local-project 创建一个新的“origin”,指向其中央(例如 github 托管)存储库,对于 template 也是如此。如果您愿意,您还可以将 local-project 中的模板远程指向中央模板存储库,而不是它的本地克隆。

I honestly still have no idea what you mean by "use reflog to bring those changes with me to the current, local project state". 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 (e.g. github-hosted) repository, and the same for 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文