For this, git commit -amend should not be used with pushed commits. It will generate a new commit and hence a new id for the amended commit. The files to add are those were into the SA before the git reset -soft was landed, and after reset these files are kept in the working directory (WD), so it is necessary add them to the SA for generate the amended commit. It makes git add with all files to add to new commit (it will be the amended commit).Everything keep how it was before the git commit command were used. It makes git reset - soft for bring back changes committed in the last commit (commit to amend) to the SA and move the index to previous commit (commit before commit to amend). However, commit 31b8e would now be unreachable.Īccording to my knowledge, amend works thus:įor git commit -amend works the changes to amend must be into the stagging area (SA) Git reset -hard put you in the following situation: Or (assuming you haven't, in the meantime, made any new commit on master, reset master, or otherwise moved the master branch reference) git checkout master # just to be sure that master is the current branch Running git checkout master # just to be sure that master is the current branch It still lives in your repository's object database, but it will eventually be deleted for good, when Git runs its periodic housekeeping, or if you trigger it explicitly by running git gc (garbage collection).Īddendum (based on Jason Baker's comment): Note that, as long as the amended commit, f42c5, still exists in your repository and you have a way of finding out its commit ID (for example, by fishing it out of the master branch's reflog), you can still check it out. Note that the amended commit ( f42c5) is now unreachable from any reference in your repository (hence its "transparent" style on my graph). The master branch reference is moved to point to that new commit ( 31b8e). Its parent(s) will be the same as that (those) of the commit you're amending: f42c5.
0 Comments
Leave a Reply. |