2017-04-12 62 views
0

可以說,我的Jave一個混帳回購協議與承諾是否可以編輯舊的git提交中的文件?

HEAD 
commit999: Edit file999 
commit998: Edit file998 
... 
commit3: Edit file3 
commit2: Edit file2 and file1 
commit1: Edit file1 

我意識到,文件1不應該在commit2編輯。我想在commit2中恢復file1上的更改,但我不想爲此恢復做出新的提交。

是否有可能做我想要的東西?如果是這樣,我該怎麼做?

(只有我用這個混帳回購協議。所以,我不在乎任何髒東西,例如,push -f origin master

+2

閱讀['git rebase --interactive'](https://git-scm.com/docs/git-rebase#git-rebase--i) – axiac

回答

0

這可以通過「修訂版本2」來完成,然後櫻桃採摘一切之上完成這....是這樣的:

git checkout commit2 git checkout HEAD~1 -- <path-to-file1> # checkout file1 as it was on the previous revision git commit --amend --no-edit # create a _new_ revision git cherry-pick commit2..commit999 # use old rev IDs for commit2 and commit999 git checkout -b new-branch # create and checkout new branch if you feel like it

這應該工作。

相關問題