用 git 踩了个坑

2021-04-13 14:21:16 +08:00
 clrss

事件顺序

  1. 添加文件 A -- commit1
  2. 一般操作 -- commit2~9
  3. git rm --cached A 并把 A 添加到 gitignore -- commit10
  4. git rebase -i commit2. 保持 commit10 不变
  5. 回放 commit10 时, 文件 A 就丢了...
2297 次点击
所在节点    git
8 条回复
yiXu
2021-04-13 14:27:11 +08:00
@clrss 没怎么看懂,能给出可复现的,所有操作的命令行代码吗? gist 给个最好,我想试试看。
momocraft
2021-04-13 14:32:56 +08:00
commit10 删掉了 A, apply 时也删掉 A 不是正常的吗?

你的期待是 apply 后 A 留在 worktree? 可是 commit 一级不保留这个信息
xuanbg
2021-04-13 14:42:23 +08:00
签出 commit9 不就回来了?
hw93
2021-04-13 15:57:07 +08:00
只要 commit 了,文件就不会丢
clrss
2021-04-13 16:08:41 +08:00
@xuanbg
@hw93

复现步骤总结错了.

实际上是
git rm A
mv /some/other/file A
dezng
2021-04-13 16:21:38 +08:00
看你上面的操作,rebase 基于 commit2,commit1 还存在,A 文件肯定还在。即使 commit1 没了,一般通过 git reflog 也能找回。
clrss
2021-04-13 16:54:17 +08:00
@dezng 看附言, 实际上是 git rm A, 然后换了个同名文件. 我要的是后来换的同名文件.
dezng
2021-04-15 10:21:16 +08:00
@clrss commit1 还在,A 一定还在 git checkout commit1 -- path/to/A 你就看到原来的 A 文件了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/770330

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX