[英]How to take local working directory to any git revision irrespective of its branch after remote changes?
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. 我正在研究一个phing构建脚本,该脚本将输入作为目标修订版本,生产代码库需要采用该修订版本。 I am preparing the same in a separate scratchpad directory and then overwriting the production codebase. 我在单独的暂存器目录中准备了相同的内容,然后覆盖了生产代码库。
Current logic 当前逻辑
Taking to the desired revision - 进行所需的修订-
git reset --hard ${target.git_version} 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). 如https://stackoverflow.com/a/1419637/351903中所述,找出其中包含所需提交的文件(已尝试过,但无法与git branch -r --contains <commit>
-似乎我丢失了关于它的概念)。
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>
. 然后git branch --contains <commit>
。
Also thought of - 还想到了-
Just checkout the commit you want to have with git checkout ${target.git_version}
. 只需使用git checkout ${target.git_version}
签出您想要的提交git checkout ${target.git_version}
。
And why wiping and re-cloning always, just a fetch
and then the checkout
should be enough. 以及为什么总是擦拭并重新克隆,只需fetch
,然后checkout
就足够了。
我的脚本“ Phingit”可以帮助您完成所需的工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.