git - git 中文件的最后一次提交显示添加的行,但文件不在项目文件夹中
问题描述
使用该命令git log --numstat
,我可以看到文件MyFile的最后一次提交显示添加了一些行。这意味着它对MyFile所做的最后一件事是有人在其中添加了一些行。
同时我在项目文件夹中找不到MyFile 。因此,我假设MyFile在某些分支中被引用,但在当前分支中没有。
这是一个正确的假设吗?如果是这样,有没有办法找到哪些分支实际上引用了MyFile?
解决方案
如果发生以下情况,这可以解释:
- 该文件已在分支 A 上删除。
- 删除发生后(按时间) ,在分支 B 上修改了相同的文件。
- 分支B合并到分支A,导致冲突,选择删除。
这是一个示例 bash 脚本来演示这一点:
#!/bin/bash -v
git init
echo asdf > asdf.txt && git add . && git commit -m "Add file asdf.txt"
git branch test-branch
rm asdf.txt && git add . && git commit -m "Delete asdf.txt"
git switch test-branch
sleep 1 # pause for one second to make sure commit datetimes are different
echo qwer >> asdf.txt && git add . && git commit -m "Add qwer to asdf.txt"
git switch main
git merge test-branch --strategy=ours --no-edit # cheat to prevent a conflict and skip the other commit
ls -la # prove there are no files
git log --numstat # the most recent commit of asdf.txt is adding a line
推荐阅读
- php - 谁能帮我在 Yii2 框架中将多个数组保存到数据库中?
- r - 在 Cox 回归中获得零 P 值:R
- python - 在python中解析列表的子列表
- c++ - cmake 错误 [SDK/Util/CMakeLists.txt:132 (add_library) 处的 CMake 错误]
- apache-kafka - Spring Cloud Stream Binding Consumer 属性不起作用
- sql - SparkSQL - 两个时间戳之间的差异(以分钟为单位)
- android - Discord OAuth2登录失败通过Android Webview
- javascript - 使用 Sequelize 在 GraphQL 查询中将日期时间字段作为字符串输出
- javascript - 如何将 JSON 转换为 Javascript 数组?
- xpath - xpath 在某个元素之后或元素之间选择文本