Search code examples
gitgithubgit-mergegit-merge-conflict

see if there is a deleted part in GitHub


when someone don't pull the latest master and then push he sees a conflict if he decided to overwrite the others code the overwritten commit don't show in the files history

the issue can be seen here https://github.com/robertIsaac/delete-test

here you can see that i added second commit https://github.com/robertIsaac/delete-test/pull/1/files

and here you can see i deleted the second commit and added the third commit https://github.com/robertIsaac/delete-test/pull/2/files

but going to the history of the file https://github.com/robertIsaac/delete-test/commits/master/delete-test.txt you see only the first and third commit which shows the addition of the first commit and third commit string to the file and second commit doesn't show at all

here is my script to replicate the issue

# 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

my question is if i faced a problem like that again how can i catch it without searching every pull request to see who deleted my code


Solution

  • Very interesting, I did not know this problem until now.

    Looks like git log --follow delete-test.txt is the solution.

    commit a0d607f5c80f2d9130bd197d9c0af1199515e8cf
    Author: robertisaacBBN <[email protected]>
    Date:   Sat Dec 1 00:46:06 2018 +0200
    
        third commit
    
    commit 168d67c24ec1de7e20c645274f64f151592d938f (origin/first-branch)
    Author: robertisaacBBN <[email protected]>
    Date:   Sat Dec 1 00:45:22 2018 +0200
    
        second commit
    
    commit 6b488fffd4b0581888e0942249a7b81e68d7db4b
    Author: robertisaacBBN <[email protected]>
    Date:   Sat Dec 1 00:45:14 2018 +0200
    
        first commit
    

    Thank the author of the original article @ https://www.shellhacks.com/git-particular-file-change-history/