0

If, for example, I create a file and commit a file, but don't push.

Then later on I realise this file is in the wrong folder and move it and commit the move.

What will happen when i push?

Is the order of commit important, or should I be removing the original commit just have it be created in the correct place from the start?

Joe Pleavin
  • 436
  • 1
  • 4
  • 21
  • 2
    You can squash the two commits into one, or you can leave them both. It is up to you which story you want to tell the readers of the history. *I* would squash them, because I do not want others to see that I have made a mistake that I fixed later. – j6t Nov 18 '22 at 10:21
  • 4
    Important for what? Some projects aim to have every single commit be valid (i.e. builds & tests), others don't care and only want a historical archive of what happened. Depending on what you want this may or may not be fine. IMO for most "non-enterprise" projects this should not be a major issue, but some might prefer a "cleaner" history. For enterprise projects the company should have rules/guidelines about this. – Joachim Sauer Nov 18 '22 at 10:22
  • 2
    Also, since I just realized you hadn't pushed yet: if you haven't pushed then it's all your choice, no one else will even realize if you did anything. Rebase/amend/squash: do whatever you want to make you happy. – Joachim Sauer Nov 18 '22 at 10:27
  • I should look at rules then before I push anything.. – Joe Pleavin Nov 18 '22 at 12:55
  • In my opinion, using git mv is also good way. Sometimes, move a file from A to B is the meaningful thing that should be clearly committed. – Manh Do Nov 18 '22 at 13:13
  • 1
    @MạnhĐỗ: it doesn't make any difference whether you use an explicit `git mv` or not: each commit has a full snapshot of all files, and if commit `a123456` has a file named X and commit `b789abc` lacks X but has Y, Git will *optionally* consider whether perhaps X was renamed to Y, and display that as a "rename", if you ask it to do so. The default used to be "I don't ask" but since Git 2.9 it is now "I do ask". If Git finds a rename this way, it displays a rename—but how file X vanished and Y appeared is not relevant! – torek Nov 22 '22 at 09:43

0 Answers0