How to take local working directory to any git revision irrespective of its branch after remote changes?

旧城冷巷雨未停 提交于 2020-01-07 02:42:44

问题


Background

I am working on a phing build script, which takes input as the target revision to which the production codebase needs to be taken. I am preparing the same in a separate scratchpad directory and then overwriting the production codebase.

Current logic

  • During every build, I am simply emptying the scratchpad and taking a fresh clone of the entire git repository in it.
  • Taking to the desired revision -

    git reset --hard ${target.git_version}

I am sure something more efficient can be done. I was thinking along the lines of -

  • finding out which one contains the desired commit, as given in https://stackoverflow.com/a/1419637/351903 (tried but could not get it working with git branch -r --contains <commit> - looks like I am missing something about the concept of it).

  • once the branch is found, cloning that particular branch only.

Then I thought of -

  • getting all the branch names only, into my local repository first (if that is possible and makes sense).

  • then git branch --contains <commit>.

Also thought of -

  • looping through all the branch names and checking if it contains a commit.

回答1:


Just checkout the commit you want to have with git checkout ${target.git_version}.
And why wiping and re-cloning always, just a fetch and then the checkout should be enough.




回答2:


My script 'Phingit' my help you doing what you want.



来源:https://stackoverflow.com/questions/37066861/how-to-take-local-working-directory-to-any-git-revision-irrespective-of-its-bran

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!