[英]Except only the last commit delete previous all commits
I am new in Git. 我是Git的新手。 I want to delete previous all commits except the last one from branch TAI-18
and want to push only the latest one for the pull request to merge with master. 我想删除TAI-18
分支中除最后一个提交以外的所有先前提交,并只想推送最新的提交,以便将请求与master合并。
For example: 例如:
commit_c
commit_b
commit_a
Where commit_a
is initial commit and except the commit_c
I want to delete all commits like commit_b
and commit_a
其中commit_a
是初始提交,除了commit_c
外,我想删除所有提交,例如commit_b
和commit_a
Can anyone help me? 谁能帮我?
Having commits: 有提交:
commit_c
commit_b
commit_a
commit_0
do git rebase -i commit_0
, you will see vi interface (or how it's configured): 做git rebase -i commit_0
,您将看到vi界面(或它的配置方式):
pick abc1234 commit_c message
pick bcd3455 commit_b message
...
change (press i to INSERT action) pick
to one of delete
/ d
/ #
that you want to remove. 更改(按i进行INSERT操作), pick
要delete
/ d
/ #
之一。 It will be removed permanently with all it's changes. 所有更改都会永久删除。
UPDATE as you say you want to keep changes, just use one commit, then you can replace pick
with squash
/ s
(except commit_c
). UPDATE像你说的,你想保留的改变,只需要使用一个承诺,那么你就可以代替pick
用squash
/ s
(除commit_c
)。 It will move anything changed from that commit to previous one. 它将更改从该提交更改为上一个提交的任何内容。
If your commit_a
is initial commit, simply reset all commits and re-do your history 如果您的commit_a
是初始提交,只需重置所有提交并重新执行历史记录
For original question: Easiest way to do this would probably be to create a new orphan branch containing the contents of the old branch: 对于原始问题:最简单的方法可能是创建一个包含旧分支内容的新的孤立分支:
git checkout commit_c #Checkout latest commit on your branch
git checkout --orphan new_branch_name
git commit
Write some reasonable commit message to describe that this commit is a squash of the old branch. 编写一些合理的提交消息,以描述此提交是旧分支的壁球。 If it looks okay, you can now move your original branch pointer to this commit: 如果一切正常,您现在可以将原始分支指针移至此提交:
git branch -f original_branch_name
For updated question: 对于更新的问题:
Seems like what you are looking for is a squash merge: 似乎您要寻找的是壁球合并:
git checkout master
git merge --squash TAI-18
This will take all the changes introduced on TAI-18
branch, and create a commit on master branch which contains all those changes. 这将采用TAI-18
分支上引入的所有更改,并在master分支上创建一个包含所有这些更改的提交。
If the same files have been updated concurrently on master branch, there may be conflicts, and you will have to resolve those. 如果在master分支上同时更新了相同的文件,则可能存在冲突,您将必须解决这些冲突。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.