The ground of being in Git is a commit, once created, is absolutely immutable. Nothing about it can ever be changed, including the hash (what you call the SHA) that uniquely identifies it.
However, during a rebase, all commits that change their parentage are copied, and the copies have the same commit message but (necessarily) a different SHA. Well, since we think of the commits "themselves" as being rebased (i.e. "moved") from one parentage to another, in that sense it is reasonable to speak loosely and say that the commits in which we are interested do change their SHA.
Here's a demonstration. We have this topology:
A -- B -- C -- D (master)
\
X -- Y (feature)
Now watch closely. I'll start on master
:
$ git log --oneline
f23b8ca (HEAD -> master) D
2dfe0fb C
ede9af5 B
a2a98f2 A
$ git checkout feature
Switched to branch 'feature'
$ git log --oneline
d621b67 (HEAD -> feature) Y
0b7c870 X
2dfe0fb C
ede9af5 B
a2a98f2 A
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: X
Applying: Y
$ git log --oneline
8440343 (HEAD -> feature) Y
13c9a39 X
f23b8ca (master) D
2dfe0fb C
ede9af5 B
a2a98f2 A
As you can see, the SHA of both Y and X "changed" as a result of the rebase.
A, B, C, and D are unchanged because they are not what was rebased. However, if, from the situation at the end of the above, you were now to do an interactive rebase where (say) you squashed C onto B, then B, D, X, and Y would all "change" their SHAs (and C would eventually cease to exist):
$ git rebase -i a2a98f2
==============
pick ede9af5 B
squash 2dfe0fb C
pick f23b8ca D
pick 13c9a39 X
pick 8440343 Y
==============
$ git log --oneline
2ea8880 (HEAD -> feature) Y
4160563 X
39847f8 D
683b128 B
a2a98f2 A
Technically, it is important to understand that no commits were actually changed! The X and Y commits after the rebase, with the "changed" SHA values, are actually new commits (copies). The "original" X and Y listed in our first log
do in fact still exist:
d621b67 Y
0b7c870 X
The difference is that we are not interested in these commits anymore. We are interested only in the new copies. And in fact, the originals no longer have any branch name preserving them, and will eventually be permitted to go quietly out of existence.