[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

猜你喜欢

转载自www.cnblogs.com/Answer1215/p/10884024.html
one