Suppose we have the following commits and we want to remove files from the second commit.
~# git log
commit 5e1552bfada408e4e3c86f1d68a50f5be71ab64a
Author: Commiter Name <commiter@git.com.br>
Date: Fri Apr 22 14:58:59 2016 -0300
Last commit
commit 3798da6a72e463c7a266518cf898643febab04e3
Author: Commiter Name <commiter@git.com.br>
Date: Wed Apr 20 21:09:36 2016 -0300
Second commit
commit 9b8dfcab524810e4ddad2b9516c323a9a6ab3857
Author: Commiter Name <commiter@git.com.br>
Date: Wed Apr 20 20:57:06 2016 -0300
First commit
We do git rebase -i with the id from the First commit
~# git rebase -i 9b8dfcab524810e4ddad2b9516c323a9a6ab3857
pick 9b8dfca First commit
e 3798da6 Second commit
pick 5e1552b Last commit
# Rebase 3cc8e8a..5e1552b onto 3cc8e8a
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
mark to edit
e 3798da6 Second commit
~# git reset --soft HEAD^
Then reset the unwanted files in order to leave them out from the commit:
~# git reset HEAD path/to/unwanted_file
Now commit again, you can even re-use the same commit message:
~# git commit -c ORIG_HEAD
Este é um blog onde anoto dicas técnicas de informática e computação. This is a blog where I write down technical tips on computing. Be aware that some resources used in this blog may use cookies to collect information used by Ads and Google Analytics. I do not monetize from this website, neither require or use personal information.
Friday, April 22, 2016
Removing files from a specific commit
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment