开发者

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. 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开发者_Python百科 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


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜