Friday, 22 November 2024

GIT checkout out commit in detached state & cherry pick info

 GIT checkout a particular commit:

https://medium.com/@Ariobarxan/checking-out-a-commit-in-git-533fe702cf23#:~:text=In%20Git%2C%20we%20can%20check,commit%20without%20affecting%20any%20branch.


In Git, we can check out specific commits directly, which results in a detached HEAD state. In this state, the HEAD pointer points directly to the commit itself rather than a branch reference. It allows you to inspect or make changes to a specific commit without affecting any branch. 


Using the Commit Hash:

If you know the commit hash, you can directly check out that specific commit. For example:


git checkout abcd1234

- fix detach state by creating a new branch after checking out commit 

When you checkout a commit, Git will update your working directory to reflect the state of that commit. However, it’s important to note that in a detached HEAD state, any changes you make will not be associated with a branch. It’s recommended to create a new branch if you intend to make changes and preserve them.


To create a new branch at the current commit while checking it out, you can use the -b flag with the git checkout command. For example:


git checkout -b new-branch-name

his will create a new branch named new-branch-name starting from the current commit and switch to it.


------------------

cherry pick is to pick commit to merge

https://www.git-tower.com/learn/git/faq/cherry-pick


In its most basic form, you only need to provide the SHA identifier of the commit you want to integrate into your current HEAD branch:

$ git cherry-pick af02e0b

No comments:

Post a Comment