![]() ![]() You can assume that if foo existed in the "old" commit and you have no new name for it, it must have been removed but if the idea of following renames is to start with an old name, this does not work in git: the -follow option only works when starting with recent history and moving back in time. There is, as far as I can tell, no good way to handle this last case. When file foo is removed, it has only an old name in the first place. ![]() That leaves out the "file was removed" case, which conflicts with the basic idea that you know the new name of the file. The -name-status part will also show if the file was created in a rev preceding the historical rev (the status will be A, added), and you will know to remove the file. Having followed the renames, you can then git checkout. This command allows you to move the HEAD and the current. Sometimes, apart from undoing the most recent commit you may also want to discard all the changes that were made to the files included in that particular commit. There's a fairly big hiccup here, as you must know the new name of the file, not the old one, but perhaps that's the case in question. One of the most straightforward methods to undo local commits is by using the git reset command. (I ran the above on the git sources themselves). You can use -name-status to observe renames, e.g.: $ git log -follow -oneline -name-status - builtin/var.cį9bc573 ident: rename IDENT_ERROR_ON_NO_NAME to IDENT_STRICTÄ¢bc8c1a var: run setup_git_directory_gently() soonerĨ1b50f3 Move 'builtin-*' into a 'builtin/' subdirectoryĦ4778d2 Make 'git var GIT_PAGER' always print the configured pager Follow, watching for rename ops, and collect them up. Here, you could use the git log -follow approach you suggested. This command will update the file in our working tree only. Weâre also specifying a commit ID to get the file as it existed at that specific commit. To do this, do a git reflog and look for the HEAD position you want to move to. What I usually do when I have to step back is reset my branch to an earlier stage. However, this in most cases is not helpful because it creates a new commit adding to your git reflog. Here, we're passing a specific path ( path/to/file) that identifies just a single file. You can always do git revert to undo a git commit.If that fails, the file must have been added, so you can simply take "failure" as "indication to remove". The most useful, general-purpose form of this command is: git checkout commit ID - path/to/file. Except for the rename issue, the general approach ( git checkout - ) you suggested first is the obvious right way to go. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |