It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Can I revert changes made in old commit?

Anton Pavelyev Dec 01, 2014


Imagine I do a little commit "B" few days ago. In that commit was file "labels.cfg".
There was many other commits since commit "B". e.g now I am at commit "F".
I want revert changes I made in "labels.cfg" in commit "B". I have another changes beetwen "B" and "F" commits in "labels.cfg" and I want to save them.

How can I do it?

1 answer

1 accepted

1 vote
Answer accepted
Tim Pettersen Dec 01, 2014

Hi Anton,

You can! The command you want is git revert. If the commit id for commit "B" is abad1, you can simply run:

git revert abad1

To create a new commit that reverts the changes introduced to label.cfg in abad1


If you don't want to commit the revert straight away you can pass the -n flag to apply the reverse patch to your working copy:

git revert -n abad1



Anton Pavelyev Dec 02, 2014

Thank you Tim! You advice helped me. But can git revert exact file/files and do it without "right away" commit? I heard git always work with full commit, so it's ideology is many small commits. Right?)

Tim Pettersen Dec 02, 2014

I'm not sure of an easy way to back out changes for just a single file - but you can prevent the commit from being created immediately by passing git revert the -n flag. I've updated my answer above.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder :  #!/bin/bash source "$(dirname "$0")/" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

3,310 views 1 22
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you