仅拉一次(最新推送)提交

问题描述 投票:1回答:1

我一直在本地存储库上工作,并多次推送到git服务器,而我在其中部署工作的服务器仍在所有这些提交之后。很快,情况是这样的:

local: commit n+5
git server: commit n+5
dev server: commit n  

现在,我只想将提交号n + 5拉到开发服务器(不包括提交n + 1,n + 2,n + 3和n + 4)。我用Google搜索并找到了一些解决方案,包括Stackoverflow上的this one。我尝试了git reset --hard <commit>,但没有成功,出现了此错误:

git status 
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
git reset --hard 77de3a5
fatal: ambiguous argument '77de3a5': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

我想尝试the other proposed solution(使用git fetchgit merge),但是当我说它时我很困惑

注意:git merge将获取所有更改及其祖先,因此,如果是最早的非合并提交,则此方法有效。恐怕这种方法将包括(拉/合并)在提交n + 5之前的所有提交。

有什么方法可以只拉一个提交(不包括先前的提交)?PS:我知道最干净的方法是使用不同的分支,但是当您有点混乱时该怎么办!

git git-pull pull
1个回答
0
投票

当然,要获取一个提交:

git fetch [remote] [branch/commit] --depth=1

该孤立的提交随后可以引用为FETCH_HEAD。在更新浅层子模块时,我经常这样做,但在其他情况下,具有孤立的无历史记录的提交可能没有用。

关于reset --hard错误,失败是因为您没有执行git fetch并且服务器还不知道存在77de3a5。

如果您只是想使开发服务器的历史记录保持整洁,您可能会想要:

git fetch
git merge --squash [commit#]

或者,如果您想避免意外引入多余的合并提交:

git fetch
git merge --ff-only [commit#]

最后,如果您只想要由该一次提交引入的更改

git fetch
git cherry-pick [commit#]
© www.soinside.com 2019 - 2024. All rights reserved.