根据提交 ID 从 git 获取代码

Tha*_*ánh 1 git bitbucket

我正在使用 git 和 bitbucket。请指导我下载或提取基于提交 ID 的所有代码的方法。例如,提交 ID 是“1”、“2”、“3”,我想要从“1”和“2”下载代码。

请帮忙!

非常感谢

Wat*_*ink 5

如果我猜对了你。当您进行初始克隆时:

git clone ssh://git@bitbucket.org:username/reponame.git -b commit_id
Run Code Online (Sandbox Code Playgroud)

当您已经克隆了存储库时:

git fetch                  # fetches all new commits from remote
git checkout commit_id     # changes current HEAD to desired commit
Run Code Online (Sandbox Code Playgroud)

或者,如果您只需要下载代码(没有 git 历史记录):

# extension zip may be changed to tar.gz for example
wget https://bitbucket.org/username/reponame/get/commit_id.zip
Run Code Online (Sandbox Code Playgroud)

小心最后一个,如果这个 repo 是私有的,你需要为 wget 指定授权。要在授权下使用 wget:

wget --http-user=username --http-password=password https://bitbucket.org/username/reponame/get/commit_id.zip
Run Code Online (Sandbox Code Playgroud)