I had a branch dev and a branch cutting-edge.
I had a commit with SHA1 id say 4356xyz on dev. I wanted that to be on cutting-edge. So I checked out cutting-edge and did
git reset --hard 4356xyz
Now when I do git log I see that history of both the branches have become same.
Is there a way by which I can recover the previous history of cutting-edge branch before I did the reset?
git reset --hard 4356xyztook yourcutting-edgebranch and pointed it at that commit. If that was the same commit thatdevwas pointing at, then yes, they will share the same history because they are now pointing at the same commit.You can inspect
git reflogto figure out what your branchcutting-edgepointed to before you told get to point it at commit4356xyz.In the future, if you want to add commits from one branch onto another, you need to either merge your branches, or cherry-pick specific commits.
To pull just commit
4356xyz, you wouldgit checkout cutting-edgeand thengit cherry-pick 4356xyz.