2 questions about working with repository history

About working with repository history in Source Tree.

  1. In order to see commits with changes to a specific only, I can filter past commits by file. What if I want to see only commits with changes to specific lines of that file?

  2. If I've understood correctly git revert HEAD~2 reverts the changes in commit Head-2, only but not those ones in commit Head-1. What if I want to revert changes in head-1 too? (without resetting and deleting past commits). Do I maybe need to checkout Head-2 and commit again?

 

2 answers

This widget could not be displayed.

At 1.) Haven't seen anything like this in any Git-GUI yet ....

At 2.) Yes you might revert both changes via two 'git revert' commands with commits meantime ... Just to be sure to revert the correct commits, I prefer to use "git reset <CommitId>' rather than HEAD~1.

2.) So if I want to revert to HEAD-2, I do need to call twice revert? Is there a simper way to revert (without using reset that is destructive command)?

Yes you would need call revert twice.

I think "git revert" is the simplest way to revert - and it is IMHO the "easiest to reproduce" way (esp. for your fellow developers)...

Have a look here: http://stackoverflow.com/questions/1463340/revert-multiple-git-commits

Thanks for the link. I've found in a comment to an answer this shortcut: git revert --no-commit D C B . I haven't tried yet, but it seems possible to revert multiple commits in one line, and then commit.

Sounds good - but I personally would be scared about what happens on reverting multiple commits at once in case of having edited the same portions of code in different commits: Hopefully git reverts the changes back in "the correct order" ...

Probably reverts in the order specified, but check the documentation to confirm. You generally want to revert the most recent first.

I Wonder what happens if I do incremental manual revert in this case, using oldest first (and most recent at last) ... Have to check this out as soon as I find some time

This widget could not be displayed.
  1. You can't do that. Partial solution: you can quickly see the most recent change to a particular line using "Blame".
  2. In the SourceTree UI, you can right click a commit and select "reverse" to undo changes in that commit. Like on the command line, this can only be done one commit at a time.

 

I've actually found this: git revert --no-commit D C B . I haven't tried yet, but it seems possible to revert multiple commits in one line, and then commit.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published May 30, 2018 in Sourcetree

Tip from the team: configuring Git or Mercurial in Sourcetree

Supported Platforms macOS Windows To make using Sourcetree as simple yet powerful as possible we embed (bundle) dependencies such as Git, Git LFS, and Mercurial. We strive to keep these...

869 views 2 3
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you