简体   繁体   English

除了最后一次提交,删除之前的所有提交

[英]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_bcommit_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操作), pickdelete / 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像你说的,你想保留的改变,只需要使用一个承诺,那么你就可以代替picksquash / 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.

相关问题 如何删除除最后五个之外的所有Git提交 - How to delete all Git commits except the last five git merge是否添加所有提交或仅提交最后一次? - Does git merge add all commits or only last commit? 如何将所有先前的提交合并为一个提交? - How to merge all previous commits into a single commit? 为什么除了最后一个提交之外所有提交都消失了? - Why all commits gone except the last one? 在特定提交后删除所有提交 - Delete all commits after a specific commit 是否可以在 GitHub 中删除远程存储库的提交历史记录(最新的除外),同时保持所有本地存储库的提交完整无缺? - Is it possible to delete a remote repository's commit history (except the latest) in GitHub while keeping all the local repository's commits intact? 如何编辑/修改Git中最后一个提交之前的提交消息? - How to edit/amend commit messages for commits previous to the last in Git? 如何提取分支的最后几个提交并重置为以前的某个提交? - How to extract last several commits to the branch and reset to some previous commit? git 命令 - 从最新的最后 8 个合并提交中获取所有文件,不包括带有消息“仅提交 Delta Changes [ci skip]”的提交 - git command- get all the files from latest last 8 merged commits excluding a commit with message “Commit only Delta Changes [ci skip]” 删除最后2次提交而不删除所有数据 - Remove last 2 commits without delete all data
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM