I was working on a project made some changes in my code (in Itellij IDE) and by mistake I did below two steps in my terminal and I saw some changes went into the main respository (not my changes or anything I had worked previously). Does anyone know why it did it ?
Note: Changes that were pushed were not my code.
- git pull ( all-upto-date, I received) from my terminal
git push (rather than "git add" and "git commit") from my terminal
- Adding additional information (edited) Yes, I had some changes in my local repository before I did a git push. But when I did the mistake of "git push" none of my local committed changes were pushed but rather someone else code was pushed which I had pulled.
I could not understand why git did that and thought of asking a question here to understand.
The question was asked to know possible cause without influencing my view on the answer.
It is difficult to say precisely what happened since you did not tell us the state of your local branch at the time you did the accidental
git pull
followed bygit push
. Assuming you started off with no local commits which did not already appear on the remote tracking branch, then I would have expectedgit push
to fail by saying that the remote is already up to date. The sign for this would be if you had rungit status
right before the accidentalgit pull
and Git told you that your branch was 0 commits ahead of the remote.For the second step, you did a
git push
. Assuming this went through, then I would interpret it to mean that you did in fact have some local commits which were not pushed yet. So, all that happened is that some of your previous local work was pushed to the repository, perhaps prematurely. Assuming those commits were made in good faith, you may have nothing to worry about. If not, then you could always revert one or more of those commits by usinggit revert
.