git - Git: add file to old commit being parent of a new branch already merged back?
问题描述
given the following git log, how do i add a file (which never existed in any commit) to commit B, so that this new file will appear in every other commit that A?
A --> B -----> D ------> F
\--> C --> E --/
In my attempts with git rebase --onto i did not succeed in not having to essentially duplicate every commit amending the contents but i am sure i am not approaching it using the full power of git. Any help?
Note: remote is fine to be forced, or even deleted and pushed again, that's not a worry.
Thanks a lot
解决方案
The end result will be that : duplicating all the commits.
About the ways to do it, though, you can use git rebase
with some options :
# -i for --interactive
# -r for --rebase-merges
git rebase -i -r A
git
will open a text editor for you, asking you to describe what actions you want to take on each commit.
In that file :
- find the line mentioning commit
B
- change the action from
pick
toedit
- save and exit
git
will start applying the script you instructed him to, and will pause after reaching B
.
At this point, you can add the extra file :
git add
the file you wantgit commit --amend
to add it toB
git rebase --continue
to proceed with the rebase
This should rewrite all the commits after B
.
You can check your local history, and the content of your commits,
if you are satisfied with the result you can push --force
.
推荐阅读
- python - 在具有多个 python 版本的 Ubuntu 18.04 中卸载所有 Python 包
- python - Python BigQuery:插入内容为数字的字符串失败
- c - C 如何正确存储 sqlite3 行数据?
- ubuntu-16.04 - Ejabberd 19 在安装时抛出“deps/.got”异常
- javascript - 如何提交从php生成的多个表单
- automated-tests - 如何在 Visual Studio 2019 中单独运行选定的测试
- yammer - 通过 Yammer 上的 API 发布富文本消息
- wordpress - plesk 子文件夹/blog wordpress nginx 404 未找到
- sql-server - 在同一台计算机上从 SQL Server Express 切换到 SQL Server Developer 版本
- matlab - 如何将 .mat 文件转换为 netCDF 文件?