The best way to explain this is with an example. Say a Senate version of a bill passes the Senate before the House companion bill passes the House. In such a case, the Senate file is transmitted to the House, and if the House companion is still in a House committee, the Senate bill is referred to that same committee. Any further action on that bill is done to the Senate bill, though the committee may insert the House language if there are differences.
If the House companion has already gone through the committee process and awaits action on the floor, then the two bills are "referred for comparison," where they are compared to one another and the differences are reported. If the bills are identical, the Senate bill is substituted for the House version and all future actions are to the Senate bill. If they are not identical, the rules must be suspended to substitute the Senate bill with its differences for the House bill.
In the House, the language of the bill that already has passed the Senate automatically takes the place of the language that was recommended by the House committee. If the chief author wants to go back to the House language, he or she makes a motion to amend and substitute the House language for the language passed by the Senate.
In the Senate, the procedure is different. When a House bill is substituted for a Senate bill on the Senate floor, the Senate automatically places the Senate language back into the bill. The Senate author must then propose an amendment if he or she wishes to use the House language.
Ultimately, both bodies must agree to any changes made to the bills. If they don't agree, the bills go to a conference committee. That committee reaches a compromise that must be accepted by both bodies. However, once a conference committee makes its recommendation, the bill cannot be amended by either the House or the Senate. The only alternative is to accept the conference committee report or send it back to the conference committee for further work.
After both bodies have passed the bill in identical form, it goes to the governor for approval or veto.