0

I'm really not that comfortable with using command-line for git, so I prefer using SourceTree, but the UI can't solve one of my problems (it reloads all the time to the top).

Actually I want to checkout the very first commit of the Swift repository (which has almost 40k commits) and then only checkout every next commit by commit and see what has changed (I'd like to learn how the language was written).

Imagine one would iterate an array from index 0 without knowing if there is a successor and which information it might have (like commit id).

Is there any script or commands I could use?

Update:

I found the answer by myself here.

moving to next commit

function n() {
    git log --reverse --pretty=%H master | grep -A 1 $(git rev-parse HEAD) | tail -n1 | xargs git checkout
}

moving to previous commit

function p() {
    git checkout HEAD^1
}
Community
  • 1
  • 1
DevAndArtist
  • 4,971
  • 1
  • 23
  • 48
  • Possible duplicate of [How do I move forward and backward between commits in git?](http://stackoverflow.com/questions/6759791/how-do-i-move-forward-and-backward-between-commits-in-git) – DevAndArtist May 19 '16 at 11:36
  • Great. See git is easy. Just learn git instead of using gui https://try.github.io/. – khrm May 19 '16 at 11:43
  • @khrm not that easy as at all. ^^ It took me a while to get these commands running as an alias. There are too many commands and parameters (it's just like `TeX`) – DevAndArtist May 19 '16 at 11:46
  • Yes. But I upvoted you because you showed perseverance. Yes, it's a bit difficult. But you can spend a day on it. and become quite proficient. Actually, that link is also not that great. Git has certain pattern. – khrm May 19 '16 at 13:39

2 Answers2

1

You could see the full history from first commit to last one. This will show all code changes (the diff). Just run: git log -p --reverse

Chananel P
  • 1,704
  • 1
  • 18
  • 19
  • Imagine initial (or 1) commit and now the `Head` is at commit 10. Would will be the result? From 1 to 10 or from 9 to 10? I need something to show only the diffs from 9 to 10. – DevAndArtist May 19 '16 at 11:16
  • 1
    If you just want to see the last diff, you can run: `git log -1 -p HEAD` – Chananel P May 19 '16 at 11:33
-1

Just go to the clone of the repo on your machine. You can get the SHA of the first commit from github. Copy the SHA of the commit you want to checkout. Do a git checkout <SHA>

Also you may do a git checkout head~n where n is the commit number counting down from head you want to refer to.

See here :

Community
  • 1
  • 1
Som Bhattacharyya
  • 3,972
  • 35
  • 54
  • 1
    That would be this: https://github.com/apple/swift/commit/18844bc65229786b96b89a9fc7739c0fc897905e. But how does he get from this one to the next child (of possibly n children)? – Boldewyn May 19 '16 at 10:04
  • Just see the SHA of the next commit and repeat the same command. – Som Bhattacharyya May 19 '16 at 10:06
  • This is ridiculous, you do know how long that will take to find every next commit from the initial one. I wasn't asking how to checkout a specific commit, but how to checkout the next commit without knowing any information of it (like indexing an array). – DevAndArtist May 19 '16 at 10:07
  • Well that was not too obvious from the question and since you said you are not to \o familiar with `git commands` ! – Som Bhattacharyya May 19 '16 at 10:08
  • I'm not familiar with them if someone would answer something like "use `checkout`" and see its docs how it works. – DevAndArtist May 19 '16 at 10:10
  • Use this then. But i do not agree with your point. Anyways try this : http://stackoverflow.com/questions/28671503/git-checkout-to-commit-number-n – Som Bhattacharyya May 19 '16 at 10:14