The commit you create replaces the current tip - if it was a merge, it will have the parents of the current tip as parents - so the current top commit is discarded. Prepare the tree object you would want to replace the latest commit as usual (this includes the usual -i/-o and explicit paths), and the commit log editor is seeded with the commit message from the tip of the current branch. Used to amend the tip of the current branch. (first stash or save b) git commit -amend If this is your last commit (and you haven't pushed it anywhere), you can amend it: Shorter: git restore -S - path/to/file/to/revertĪgain, you then can git commit -amend, as I originally wrote below. If you really want to undo the commit, you. The difference is that a soft reset leaves the files staged for commit, which is not what it sounds like you want to do. With Git 2.23 (August 2019), you might use the new git restore command git restore -source=HEAD^ -staged - path/to/file/to/revert I would leave off the -soft in the other two answers and go with a simple git reset (or git reset HEAD in older versions of git), which will default to git reset -mixed. Then you can git commit -amend, as I originally wrote below. HEAD^ allows the file to access its content in the previous commit before the last one. True: you can reset a file to its index content easily enough, as the more recent answer (written by Matt Connolly) suggests: git reset HEAD^ path/to/file/to/revert It's trivial to remove it from index only.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |