Showing posts with label GIT. Show all posts
Showing posts with label GIT. Show all posts

Wednesday, 23 July 2025

GIT precommit hooks

 .git/hooks/precommit


write a bash script, will be executed after git commit 


Create a file named pre-commit (without any extension) in your .git/hooks/ directory within your Git repository. Ensure this file is executable (chmod +x .git/hooks/pre-commit).


precommit need to check pwd see where root folder is

code check bin using go 

https://github.com/Done-0/fuck-u-code


GIT does not upload this to remote, so it must be local 

#!/bin/bash

pwd

# Define the path to your Go executable

GO_EXECUTABLE=".git/hooks/fuck-u-code"


# Check if the Go executable exists

 if [ ! -f "$GO_EXECUTABLE" ]; then

     echo "Error: Executable '$GO_EXECUTABLE' not found in the same directory as the hook."

         exit 1

         fi



# Run the Go executable

"$GO_EXECUTABLE" analyze  rootsubfod1/cli


# Check the exit status of the Go executable

if [ $? -ne 0 ]; then

             echo "Check code failed. Aborting commit."

                 exit 1

fi


echo "Check code finished successfully. Please record the analysis, proceeding with commit."

exit 0


Thursday, 24 April 2025

GIT convenient commands

Revert a specific directory to a commit 

 https://stackoverflow.com/questions/30844254/undo-changes-made-in-a-specific-folder-in-git

git checkout --no-overlay <commit> -- <directory>


Merge a specific commit

https://stackoverflow.com/questions/881092/how-to-merge-a-specific-commit-in-git


#to merge the commit need to go to that branch pull first

git cherry-pick d42c389f

Thursday, 19 December 2024

GIT LAB VS GIT HUB

 GIT LAB and GIT HUB are all based on GIT

GIT LAB is open source and can be hosted on ur own, however git hub is not.

Wednesday, 11 December 2024

Github - unexpected disconnect while reading sideband packet

 https://stackoverflow.com/questions/66366582/github-unexpected-disconnect-while-reading-sideband-packet

Github - unexpected disconnect while reading sideband packet


  1. Switch to HTTPS origin URL: git remote set-url origin https://github.com/<your_repo>
  2. Do the push. It should not fail now.
  3. Switch back to SSH: git remote set-url origin git@github.com:<your_repo>

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

Monday, 29 July 2024

GIT cherry pick , GIT revert a revert of merge request

 GIT revert a revert of merge request

    use GIT cherry pick

https://stackoverflow.com/questions/9339429/what-does-cherry-picking-a-commit-with-git-mean


Cherry-picking in Git means choosing a commit from one branch and applying it to another.

This contrasts with other ways such as merge and rebase which normally apply many commits to another branch.

It's also possible to cherry-pick multiple commits but merge is the preferred way over cherry-picking.

  1. Make sure you are on the branch you want to apply the commit to.

    git switch master
    
  2. Execute the following:

    git cherry-pick <commit-hash>