⭐️ 更多前端技术和知识点,搜索订阅号
JS 菌
订阅
有时候咱们须要修改 git 历史提交的文件内容,若是只是在前一个 commit,那么只须要修改文件并执行 --amend
便可:前端
如修改上一次提交的文件:vue
// do something git add . git commit --amend --no-edit
另外,可能还须要修改以往历史提交的文件,那么就须要使用到 rebase:git
git log 查看一下以往的提交纪录:ide
commit 084dbd48be6fff86b0d3de23220cff8cabddd9c6 (HEAD -> master) Author: oli <oli@olideMacBook-Pro.local> Date: Thu May 9 23:20:09 2019 +0800 echart how to use commit 3358a5fd3078d7fb6794d8c2d468054db300a46f Author: oli <oli@olideMacBook-Pro.local> Date: Wed May 1 11:26:12 2019 +0800 edit Readme.md commit c0b7ac77431ceb270b5f0aa0f97b13a79afca4b9 Author: oli <oli@olideMacBook-Pro.local> Date: Wed May 1 02:25:40 2019 +0800 init
假设咱们须要修改第二条纪录中的项目的文件,那么之行命令:ui
git rebase 3358a5fd3078d7fb6794d8c2d468054db300a46f^ --interactive
spa
将 pick3d
pick 3358a5f edit Readme.md pick 084dbd4 echart how to use
改成 editcode
edit 3358a5f edit Readme.md pick 084dbd4 echart how to use
而后保存rem
Stopped at 3358a5f... edit Readme.md You can amend the commit now, with git commit --amend Once you are satisfied with your changes, run git rebase --continue
按照提示,修改文件而后使用 git commit --amend
提交,并调用 git rebase --continue
便可:it
diff --git a/README.md b/README.md index 73ae153..98b8201 100644 --- a/README.md +++ b/README.md @@ -1,29 +1 @@ -# vuebox - -## Project setup -``` -yarn install # ... +Read the guide and start building things in no time!
修改文件后提交:
git add . && git commit --amend --no-edit
> running pre-commit hook: lint-staged No staged files match any of provided globs. [detached HEAD 4436ffc] edit Readme.md Author: oli <oli@olideMacBook-Pro.local> Date: Wed May 1 11:26:12 2019 +0800 11 files changed, 177 insertions(+), 131 deletions(-) # ...
最后调用 git rebase --continue
Successfully rebased and updated refs/heads/master.
搞定~
请关注个人订阅号,不按期推送有关 JS 的技术文章,只谈技术不谈八卦 😊