We will discuss techniques for editing a branched history in Chapter 10. Note that most of the techniques discussed in this chapter only make sense when the portion of history involved is linear that is, contains no merge commits. The extra step afforded by Git is crucial, though: by separating committing and publishing, it allows you to use version control freely for your own purposes as you work, then clean up your commits for public consumption before publishing them. You are free to delete or change your local commits as you please, and Git gives you the tools to do that publishing those commits is a separate action, via pushing to shared repository or asking others to pull from yours.Ĭhanging already published commits is awkward, of course, since it would cause others to lose history they already have Git will warn people pulling from you of that, and you might not even be allowed to push such changes to a shared repository. With Git, however, this is not a problem, since you are committing to your own private repository. This makes undoing a commit problematic how do you retract a commit others have already checked out or merged? With centralized version control, committing and publishing a change are the same thing: as soon as you commit to the shared repository, others can see and start using your changes. This chapter is about undoing or correcting changes once youâve committed them. # Successfully rebased and updated refs/heads/master.In Chapter 3, we discussed staging changes in the index for inclusion in the next commit. # continue running the last two commands until you see # edit the file to read "edit for each entry Git checkout and rebase it onto your new root commit # now you've changed the commit message, so checkout the original branch again Git commit -amend -author "Foo (or if you've set the proper git **config** values) # check it out on its own temporary branch Git tag root `git rev-list HEAD | tail -1` # create a temporary tag for the root-most commit so we can reference it Git reset -hard $BRANCH2 # be careful with this commandĬombining the answer from How do I fix the metainformation on the first commit in git? # Fix the first commit # The original branch ref can be reassigned to the new one, and the new one deleted: git checkout $BRANCH mapfile and do: git checkout -b $BRANCH2 $START So when you need to correct authors, now you just then need to generate a. Reauthor = !sh -c 'eval `git log -reverse -topo-order -pretty=format:\"git cherry-pick %H & git commit -amend -C %H -author=\\\"%aN \\\" & \" $0 ` "echo success" ' This is also generally applicable - put this in your ~/.gitconfig: For each commit between $START and then end of $BRANCH, the second command cherry picks the original commit on to the end of the current branch $BRANCH2, and amends it to set the author correctly. The first command creates a new empty branch sprouting from the commit $START. Git log -reverse -pretty=format:"cherry-pick %H commit -amend -author='%aN ' -C %H" $START.$BRANCH | sh. mailmap file like this (say): You you can use git log's formatting feature to generate the commands to rewrite $BRANCH as $BRANCH2. You can get a list of the existing author names with: git shortlog -se mailmap file in the top directory of your repository which maps the existing author names to he correct ones. We can use it to generate the commands to pick and amend amend a named sequence of commits.įor example, suppose you want to correct the authorship on a branch $BRANCH, starting at a commit $START. This provides an author mapping mechanism we can use with git log's formatting facility. mailmap feature described in the git-shortlog manpage. Here's an alternative I found useful, which uses the. Git's filter-branch command is powerful, but it's horribly unwieldy to use for anything non-trivial, like for example, if you have more than one author to correct.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |