In this chapter we shall learn about below GIT commands.
git hooks
git ignore
git attributes
git prune
git show
git hooks
* “git hooks” are custom scripts that run whenever a particular event occur.
* They are present in “.git/hooks” directory.
* Below are the sample files that you get:
applypatch-msg.sample
pre-push.sample
commit-msg.sample
pre-rebase.sample
post-update.sample
prepare-commit-msg.sample
pre-applypatch.sample
update.sample
pre-commit.sample
* To use these hooks, remove the “.sample” extension.
* For example, in “pre-commit” you can write a script that will do a unit testing of the changes, so that the commit will not break anything.
* So this “pre-commit” hook will run, prior to commit.
git ignore:
“git ignore” is used to ignore some of the auto generated files or object files.
“.gitignore” file is used to ignore all the files that we dont want to be tracked.
We can put the list of files that are needed to be ignored.
If you have that file then open it or else to create the file, go to the local repository then “gvim .gitignore”
In git ignore file, we need to write only one expression per line, example shown below:
*.obj
filename.abc
my-folder/
My “.gitignore” file is as below
In the current directory I have below files:
as we have put “filename.abc” file in “.gitignore”, it will not be tracked, we can see it in “git status” command.
git attributes
* Similar to .gitignore, .gitattributes file is used to create a visual understanding of the files, when you do “diff”.
* You can follow below link for more .gitattributes settings for different languages.
https://github.com/alexkaratarakis/gitattributes
git prune
* when you make a copy of remote repository that has many branches, and those branches will be copied to your local repository.
* When the remote repository will merge those branches, there is an option available in remote repository to delete that branch.
* To delete the local branches, we use “git prune”.
* To know the branch that are unreachable use “git remote prune origin –dry-run” command.
* To delete those branches use “git remote prune origin” command.
git show
“git show <commit-id/sha>” command is used to show the metadata and content changes for the specified commit.