我不得不还原一个提交。现在,我修复了代码,我想用我已更改的文件以及已更改的原始文件创建请求请求。但是,只有第一次提交以来的文件才会显示在拉取请求中。我如何告诉git也更新原始文件?
我基于固定分支创建了一个新分支,但是即使在新分支中它们是正确的,它也忽略了属于原始提交的文件。
答案 0 :(得分:1)
我将从上一次提交开始创建一个新分支,并执行以下操作:
Sidenote :如果可能的话,我总是更喜欢重置分支而不是还原更改,特别是如果我知道有一天需要重新整合它们。如果要恢复的提交是最后一次提交并且最近已推送,则重置分支是一个好主意,因此希望没人下载它。
答案 1 :(得分:0)
听起来像您可以使用squash
来合并您的提交。为此,请看interactive rebase。如果您尚未推送更改,这尤其优雅,因为您基本上可以撤消两次还原提交,以避免在主存储库中造成混乱。
还请记住,您始终可以检出文件上的增量,并仅暂存所需的更改:
git checkout <branch> -- <filename>
答案 2 :(得分:0)
以下是还原提交并在单个“还原”提交中进行更改的过程:
创建示例提交
/mnt/c/git/ConsoleApp1 (master)>echo Text > x.txt
/mnt/c/git/ConsoleApp1 (master)>git add --all
/mnt/c/git/ConsoleApp1 (master)>git commit -am "A commit"
[master 07852fa] A commit
1 file changed, 1 insertion(+)
create mode 100644 x.txt
创建一个还原提交,以还原示例提交并添加额外的更改
/mnt/c/git/ConsoleApp1 (master)>git checkout -b feature/with_revert
Switched to a new branch 'feature/with_revert'
/mnt/c/git/ConsoleApp1 (feature/with_revert)>git log -n1
commit 07852fac90b5debcfdd3ea67c282c1fee77e59e6
Author: Tymtam
Date: Tue Aug 21 13:28:21 2018 +1000
A commit
/mnt/c/git/ConsoleApp1 (feature/with_revert)>git revert --no-commit 07852fac90b5debcfdd3ea67c282c1fee77e59e6
/mnt/c/git/ConsoleApp1 (feature/with_revert|REVERTING)>git status
On branch feature/with_revert
You are currently reverting commit 07852fa.
(all conflicts fixed: run "git revert --continue")
(use "git revert --abort" to cancel the revert operation)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: x.txt
/mnt/c/git/ConsoleApp1 (feature/with_revert|REVERTING)>echo Text2 > y.txt
/mnt/c/git/ConsoleApp1 (feature/with_revert|REVERTING)>git add y.txt
/mnt/c/git/ConsoleApp1 (feature/with_revert|REVERTING)>git status
On branch feature/with_revert
You are currently reverting commit 07852fa.
(all conflicts fixed: run "git revert --continue")
(use "git revert --abort" to cancel the revert operation)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: x.txt
new file: y.txt
/mnt/c/git/ConsoleApp1 (feature/with_revert|REVERTING)>git commit
[feature/with_revert 902e37f] Revert "A commit" + changes
2 files changed, 1 insertion(+), 1 deletion(-)
delete mode 100644 x.txt
create mode 100644 y.txt
/mnt/c/git/ConsoleApp1 (feature/with_revert)>git log -n2
commit 902e37f76cabe0e144e091344e8c11ab6dd5213b
Author: Tymek Majewski <tymek@redbacktech.com>
Date: Tue Aug 21 13:29:30 2018 +1000
Revert "A commit" + changes
This reverts commit 07852fac90b5debcfdd3ea67c282c1fee77e59e6.
commit 07852fac90b5debcfdd3ea67c282c1fee77e59e6
Author: TymTam
Date: Tue Aug 21 13:28:21 2018 +1000
A commit