![]() RefsĪ ref is an indirect way of referring to a commit. Instead of parsing the commit reference manually, you can let git rev-parse normalize the input for you. This is particularly useful when writing custom scripts that accept a commit reference. ![]() The following returns the hash of the commit pointed to by the main branch: git rev-parse main For this, you can use the git rev-parse command. It’s sometimes necessary to resolve a branch, tag, or another indirect reference into the corresponding commit hash. For example, you can inspect the above commit with git show by running the following command: git show 0c708f When passing the commit to other Git commands, you only need to specify enough characters to uniquely identify the commit. You can find the hash of all your commits in the git log output. This acts as the unique ID for each commit. The most direct way to reference a commit is via its SHA-1 hash. We’ll also learn how to revive seemingly “lost” commits by accessing them through Git’s reflog mechanism. In this chapter, we’ll shed some light on the internal workings of common commands like git checkout, git branch, and git push by exploring the many methods of referring to a commit. For example, you can use git checkout to view an old commit by passing in a commit hash, or you can use it to switch branches by passing in a branch name.īy understanding the many ways to refer to a commit, you make all of these commands that much more powerful. ![]() ![]() The majority of these commands operate on a commit in some form or another, and many of them accept a commit reference as a parameter. Git is all about commits: you stage commits, create commits, view old commits, and transfer commits between repositories using many different Git commands. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |