将先前提交的文件合并到当前头部
Merging files from previous commit to current head
我曾经提交过 master 分支,但出于某种原因我又恢复了。现在几个月过去了,我想再次将这些更改包含在我的代码中。我想在我的本地存储库中通过在我的本地存储库中创建一个新的 master 分支并添加来自还原提交的更改来执行此操作。对我如何去做有帮助吗?
您可以轻松地从 master 创建一个新分支,您可能已经知道:
git checkout master
git checkout -b mynewbranch
如果您只想从一个还原的提交中提取更改,最简单的方法是通过其 ID 挑选它。请注意,这将是您还原的提交的 ID;不是还原本身的 ID。
git cherry-pick {ID}
根据更改的上下文,这可能会或可能不会导致冲突。如果确实如此,那么您将不得不解决它。
如果您安装了 Git GUI,cherry-pick
进行多次提交会更容易。
1. Checkout the `master` branch
2. Visualize the `master` branch's history
Repository > Visualize master's History
3. Checkout to the new branch from the main GUI window.
4. From the master's History window, scroll to the required commit(s), right-click
"Cherry-pick this commit"
这会将提交添加到当前活动分支,并且可能需要解决出现的任何冲突。
我曾经提交过 master 分支,但出于某种原因我又恢复了。现在几个月过去了,我想再次将这些更改包含在我的代码中。我想在我的本地存储库中通过在我的本地存储库中创建一个新的 master 分支并添加来自还原提交的更改来执行此操作。对我如何去做有帮助吗?
您可以轻松地从 master 创建一个新分支,您可能已经知道:
git checkout master
git checkout -b mynewbranch
如果您只想从一个还原的提交中提取更改,最简单的方法是通过其 ID 挑选它。请注意,这将是您还原的提交的 ID;不是还原本身的 ID。
git cherry-pick {ID}
根据更改的上下文,这可能会或可能不会导致冲突。如果确实如此,那么您将不得不解决它。
如果您安装了 Git GUI,cherry-pick
进行多次提交会更容易。
1. Checkout the `master` branch
2. Visualize the `master` branch's history
Repository > Visualize master's History
3. Checkout to the new branch from the main GUI window.
4. From the master's History window, scroll to the required commit(s), right-click
"Cherry-pick this commit"
这会将提交添加到当前活动分支,并且可能需要解决出现的任何冲突。