查看GitHub中是否有已删除的部分

时间:2018-11-30 23:33:14

标签: git github git-merge git-merge-conflict

当某人不拉最新的大师然后再推他看到冲突时 如果他决定覆盖其他代码,则覆盖的提交不会显示在文件历史记录中

问题可以在这里看到 https://github.com/robertIsaac/delete-test

在这里您可以看到我添加了第二个提交 https://github.com/robertIsaac/delete-test/pull/1/files

在这里您可以看到我删除了第二个提交并添加了第三个提交 https://github.com/robertIsaac/delete-test/pull/2/files

但要转到文件的历史记录 https://github.com/robertIsaac/delete-test/commits/master/delete-test.txt 您只会看到第一次提交和第三次提交,显示了第一次提交和第三次提交字符串添加到文件中,而第二次提交根本不显示

这是我的脚本来复制问题

# delete-test script
# you need to create a repo named delete-test 
# and replace the https://github.com/robertIsaac by your user name in the two lines using them
# the second next two lines can be skipped if its your first time running the script
rm -rf ~/github
rm -rf ~/delete-test
mkdir ~/github
cd ~/github
echo "first commit" >> delete-test.txt
git init
git add .
git commit -m "first commit"
git remote add origin https://github.com/robertIsaac/delete-test.git
git push -u origin master
git pull
cd ~
git clone https://github.com/robertisaac/delete-test.git
cd ~/github
git checkout -b first-branch
echo "second commit" >> delete-test.txt
git add .
git commit -m "second commit"
git push origin first-branch

## go merge with master (no conflict)

cd ~/delete-test
git checkout -b second-branch
echo "third commit" >> delete-test.txt
git add .
git commit -m "third commit"
git push origin second-branch

## go merge and resolve conflict by accepting second-branch changes and deleting the master changes

我的问题是,如果我再次遇到类似的问题,如何在不搜索每个拉取请求的情况下捕获到谁删除了我的代码

1 个答案:

答案 0 :(得分:1)

非常有趣,直到现在我才知道这个问题。

看起来像git log --follow delete-test.txt是解决方案。

commit a0d607f5c80f2d9130bd197d9c0af1199515e8cf
Author: robertisaacBBN <robert.isaac@businessboomers.net>
Date:   Sat Dec 1 00:46:06 2018 +0200

    third commit

commit 168d67c24ec1de7e20c645274f64f151592d938f (origin/first-branch)
Author: robertisaacBBN <robert.isaac@businessboomers.net>
Date:   Sat Dec 1 00:45:22 2018 +0200

    second commit

commit 6b488fffd4b0581888e0942249a7b81e68d7db4b
Author: robertisaacBBN <robert.isaac@businessboomers.net>
Date:   Sat Dec 1 00:45:14 2018 +0200

    first commit

感谢原始文章的作者@ https://www.shellhacks.com/git-particular-file-change-history/