I am new to GIT and face scenario as follow:
push file below:
index.php
$name = "steve";
echo("good morning");
echo($name);
pull the file and then remove the $name variable by accidentally.
echo("good morning");
echo($name);
Without realizing it, pull and push the new code to server. Problem is the code is broke and no longer working, GIT won’t prompt for removal of the line. Is there anyway to solve such scenario?
To be able to handle this, Git would need to have a knowledge of the content that you’re pusing. In your case, Git would have to know that removing
$name = "steve";in a.phpfile would produce an error.But this could be perfectly fine for plain
.txtfile where you’re just writing text.Not the
pulloverrides the previous code but you did. You removed the line, you told Git to commit that version, you pulled that version from the remote repo. And all that went good.The best way to solve such a scenario is avoiding it by testing your code before pushing.
If that scenario occurs in spite of careful testing, you could of course use Git to restore the last version that was checked in and working using
where
<SHA-HASH>is the commit-ID of the last good version ofindex.php.