如何在远程更改后将本地工作目录转移到任何git修订版而不考虑其分支? [英] How to take local working directory to any git revision irrespective of its branch after remote changes?
问题描述
p
我正在研究phing构建脚本,它将输入作为生产代码库所需的目标修订版拍摄。我正在准备一个单独的 scratchpad 目录,然后覆盖生产代码库。
$ b 当前逻辑
- 在每个构建过程中,我只是清空暂存器并对其中的整个git存储库进行全新克隆。
-
考虑到所需的版本 -
git reset --hard $ {target.git_version}
我相信可以做更高效的事情。我正在考虑 -
-
找出哪一个包含所需的提交,如https://stackoverflow.com/a/1419637/351903 (试过,但不能让它与
git分支工作 - r --contains< commit>
- 看起来我错过了它的概念)。
-
一旦找到分支,只克隆该分支。
然后我想到 -
-
仅将所有分支名称存入我的本地存储库中
。 - 遍历所有分支名称并检查它是否包含提交。 >只需使用
git checkout $ {target.git_version}
。>
签出您想要的提交。为什么总是擦除和重新克隆,只是一个fetch
,然后checkout
应该足够了。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.
解决方案Just checkout the commit you want to have with
git checkout ${target.git_version}
.
And why wiping and re-cloning always, just afetch
and then thecheckout
should be enough.这篇关于如何在远程更改后将本地工作目录转移到任何git修订版而不考虑其分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
还想过 -