![]() ![]() But you did not ask how to do that, so let's not confuse things more. Maybe instead you'd like the superproject to record the submodule's current commit. (The fact that the submodule is on the "wrong" commit is suggestive though: it means that maybe you don't want to force the submodule back to the superproject's recorded commit. The git submodule command has a lot of modes the update -checkout mode says using the current superproject commit, find the $hash value, and then run the above git -C command to check out that commit within the submodule. Where do you get that hash ID? Well, the easy way is to let Git fish it out for you, by running: git submodule update -checkout MyApp/mylib Where $hash is the hash ID that the superproject (i.e., your current commit in your repository) is calling for. To force the submodule back to the commit that the superproject calls for, you need to have Git itself run: git -C MyApp/mylib switch -detach $hash The first example will restore the file as it was in commit #7173808e, while the second one will restore it as it was "two commits before the current tip of the master branch".The modified (new commits) status really just means that the submodule is currently "on" a different commit than the superproject calls for. ![]() $ git restore -source master~2 index.html Keep in mind, however, that you cannot undo this! $ git restore index.htmlĪnother interesting use case is to restore a specific historic revision of a file: $ git restore -source 7173808e index.html If you want to discard uncommitted local changes in a file, simply omit the -staged flag. You can of course also remove multiple files at once from the Staging Area: $ git restore -staged *.css If some of the commits between SHA and the tip of your branch are merge commits, it is possible that git rebase -p will be unable to properly recreate them. To only unstage a certain file and thereby undo a previous git add, you need to provide the -staged flag: $ git restore -staged index.html Obviously replace 'SHA' with the reference you want to get rid of. Using the Tower Git client, you can easily select the exact chunks & lines you want to stage, unstage, or even discard: Tip Discarding / Unstaging Chunks or Even Lines of Changes Git steps through all of the individual chunks of changes in an interactive way and asks you, for each chunk, if you want to discard/unstage it. patchĪllows you to select individual chunks to restore. The -source option, however, allows you to restore the file at a specific revision. By default, the file will be restored to its last committed state (or simply be unstaged). Restores a specific revision of the file. With the -staged option, however, the file will only be removed from the Staging Area - but its actual modifications will remain untouched. By default, the git restore command will discard any local, uncommitted changes in the corresponding files and thereby restore their last committed state. Removes the file from the Staging Area, but leaves its actual modifications untouched. ![]() character, thereby restoring all files in the current directory. ![]() But you can also provide multiple filenames (delimited by spaces) or even a wildcard pattern (e.g. Naming the file you want to restore can be as simple as providing the filename / path to a single file. The name of a file (or multiple files) you want to restore. On the other hand, the restore command can also be used to discard local changes in a file, thereby restoring its last committed state. On the one hand, the command can be used to undo the effects of git add and unstage changes you have previously added to the Staging Area. The "restore" command helps to unstage or even discard uncommitted local changes. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |