How can I reset or revert a file to a specific revision?

前端 未结 30 1944
不思量自难忘°
不思量自难忘° 2020-11-21 11:23

I have made some changes to a file which has been committed a few times as part of a group of files, but now want to reset/revert the changes on it back to a previous versio

30条回答
  •  太阳男子
    2020-11-21 11:50

    Here's how rebase works:

    git checkout 
    git rebase master
    git checkout master
    git merge 
    

    Assume you have

    ---o----o----o----o  master
        \---A----B       
    

    The first two commands ... commit git checkout git rebase master

    ... check out the branch of changes you want to apply to the master branch. The rebase command takes the commits from (that are not found in master) and reapplies them to the head of master. In other words, the parent of the first commit in is no longer a previous commit in the master history, but the current head of master. The two commands are the same as:

    git rebase master 
    

    It might be easier to remember this command as both the "base" and "modify" branches are explicit.

    . The final history result is:

    ---o----o----o----o   master
                       \----A'----B'  
    

    The final two commands ...

    git checkout master
    git merge 
    

    ... do a fast-forward merge to apply all changes onto master. Without this step, the rebase commit does not get added to master. The final result is:

    ---o----o----o----o----A'----B'  master, 
    

    master and both reference B'. Also, from this point it is safe to delete the reference.

    git branch -d 
    

提交回复
热议问题