Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??

Not a git expert, but a quick test seemed to show me that git reset --soft 2.12_002 will leave the changes from the newer versions in the index, I don't think that's what you want, because a commit afterwards would put those changes back into the repo.

If you want to begin your work with a commit that undoes all the changes since 2.12_002, the following seems to work, even directly on master.

git revert --no-commit 2.12_002.. git commit -m "Rewind to tag 2.12_002" # continue work here

Another approach might be to base the new branch on 2.12_002 and then later merge that branch back into master, clobbering all the changes in master at the same time auto-resolving all conflicting hunks by favoring the start-anew branch. (Update 2: Changed wording of the previous sentence after re-reading the git-merge docs. This is a significant difference because changes in the master branch that don't conflict will still be reflected into the merge result! Perhaps the "ours" instead of "recursive" merge strategy might be better for clobbering, untested. If in doubt, use the above solution instead!)

git checkout -b start-anew 2.12_002 # - make edits here - git checkout master git merge -s recursive -X theirs \ -m 'Merge branch "start-anew" (based on 2.12_002)' \ start-anew git branch -d start-anew git log --oneline --decorate --graph

Update: Here's how I generated the fake repo for testing:

git init echo -e "Hello, World\n---" >foo.txt git add foo.txt git commit -m 'Initial commit' for VER in 001 002 003 004 do VER="2.12_$VER" echo -e "Added in $VER\n---" >>foo.txt git commit -am "Edit for $VER" git tag $VER done

And similarly the fake edit:

echo -e "Added in 2.12_005\n---" >>foo.txt git commit -am "Edit for 2.12_005"

Update 2017-04-21: Just noticed this cross-posting to perl.module-authors. Also, it appears we're talking about File::Path version 2.12_004 (GitHub).


In reply to Re: [OT] What is best practice for 'git reset'? (updated) by haukex
in thread What is best practice for 'git reset'? by jkeenan1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.