Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
204 views
in Technique[技术] by (71.8m points)

How to unsquash git commit?

After a merge of a pull request from master to staging, all commits (100+) from master were squashed to 1 commit. Then some time passed and there are ~200 new commits at staging.

Now in Visual Studio "Git blame" shows all related changes to that PR just as merge commit instead of original commits from the master, so it's difficult to see history.

Is there are any way to "unsquash" this commit, so it would show again all original commits from develop instead of a single merge commit?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If the 100 initial commits are still on master : you can use git replace in your repo to, locally, have a view where the 100 commits are part of your staging branch :

git replace <squash commit id> <original commit id>

# to list existing replacements in your local repo :
git replace -l

# to delete a replacement :
git replace -d <object id>   # <- <squash commit id> in your case

Check git help replace for more details.


emphasize on the locally :

the swapping of commits will not be shared with the central repo, nor with other users.

On your local clone, git will view the commit graph differently, and some commands will not have the same result as on other machines.

For example : with the above replacement active, if from your staging branch you run git merge master :

  • your local repo will consider that the 100 commits from master are already merged,
  • any other clone will try to re-merge the 100 commits, and trigger different merge conflicts.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...