zoukankan      html  css  js  c++  java
  • [Git] How to revert one file changes from one commit

    Many times we might changed one file which we don't intent to do... but it was too late, until we found it, it is already push to repo.

    Let's assume,

    First, we checkout a feature branch, we have two files:

    a.txt:

    Init a

    b.txt:

    Init b

    This is original state. Let's assign a commit id: a111.

    Now we made a mistake, we changed a.txt by mistake, in the mean while we are also doing some work in b.txt:

    a.txt:

    I don't know this changes

    b.txt:

    I want to keep this changes

    You can have as many commit as you want:

    ...

    Now we found that a.txt shouldn't be changed

    git checkout a111 src/a.txt // checkout <commit id> <filename>
    git status
    git add .
    git commit -am "revert a.txt"
    git push

  • 相关阅读:
    bzoj1648
    bzoj3404
    bzoj1650
    bzoj1625
    bzoj1606
    bzoj1464
    bzoj1572
    bzoj1617
    bzoj1092
    bzoj1091
  • 原文地址:https://www.cnblogs.com/Answer1215/p/10884024.html
Copyright © 2011-2022 走看看