Skip to content

Instantly share code, notes, and snippets.

@chrisroos
Created January 13, 2017 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisroos/2f4abc33b7b8a0326b6c54495395c17f to your computer and use it in GitHub Desktop.
Save chrisroos/2f4abc33b7b8a0326b6c54495395c17f to your computer and use it in GitHub Desktop.

GitHub commit ordering

GitHub's ordering of commits is explained in their "Why are my commits in the wrong order" help page.

  1. Create new repo on GitHub

  2. Clone locally to /tmp/

    $ cd /tmp
    $ git clone <repo>
    $ cd <repo>
  3. Create branch

    $ git co -b testing-order-of-github-commits
  4. Add three files

    $ touch file1 && git add file1 && git commit -m 'add file1'
    $ touch file2 && git add file2 && git commit -m 'add file2'
    $ touch file3 && git add file3 && git commit -m 'add file3'
  5. Push the branch to GitHub

    $ git push -u origin testing-order-of-github-commits
  6. Create a Pull Request from the branch

  7. Observe the order of the commits is:

  • add file1
  • add file2
  • add file3
  1. Rewrite the local branch and change the order of the commits to:
  • add file3
  • add file1
  • add file2
  1. Force push the branch to GitHub

    $ git push -f origin testing-order-of-github-commits
  2. Observe that the order of the commits on GitHub remain unchanged:

  • add file1
  • add file2
  • add file3

I don't think there's any way to use the git command line client to replicate the order of the commits in GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment