您不能修改以前的提交。每个提交都是唯一的。
您可以做的是使用新提交重新创建历史记录。使用命令git-rebase
I understand that you are in this point now:
Pre_A - A - B
\
A1
You have lost your "B" Commit. To recover the commit use git-reflog
git reflog
You will see the latest position of the branch HEAD
. One of them is the B commit. Write down the Hash of the beginning of the line. Example:
git reflog
a123b Ammend Commit of Previous A that generates A1 commit
b234c git reset soft to A Commit
c345d B Commit
b234c A Commit ##Look that the HASH is the same that the git-reset##
Once you have the HASH of the B Commit. Create a branch to recover the commit.
git branch tmpBranch c345d
At this point, what you need is to put this commit in the new history of "A1" instead of being in "A". You get this using git-rebase
I assumpt that you were working in your master branch.
git checkout tmpBranch
git rebase --onto master tmpBranch~1 tmpBranch
This recreate the history from one commit backward of tmpBranch commit until tmpBranch commit (in your case only one commit, The B commit) in master (that points to A1 commit).