If you make any mistake in your commit you can amend it rather than making a new commit. Like if you did not include the necessary files or did not write the commit message properly you can edit that previous commit rather than making a new commit. Like if forget to add a file then I need to add this file first like
git add forgotterFile.html
Then I need to amend the commit like this
git commit --amend
This will open the editor for writing the commit message. If we need to change the commit message we can update it here otherwise just close the tab/editor and press enter.
Ignore Files or Directories from git
As we previously see that if we run git add --all or git add . , all the changed files and directories added to the staging point. If we do not want to track some files or folders we can do that with the help of .gitifnore file. Suppose generally programmers do not want to maintain node_modules folder for their NodeJs project or vendor directory for their PHP project, as they increase the maintaining bundle size when we push them any remote repository. And those resources or contents can be easily downloaded with the help of package.json or composer.json file. So we can maintain the project properly by those files rather than adding the large resource directory.
Sometimes we don't want to maintain some secrete files or data to the git like password, credit card information, photos, or something. It might cause dangerous security issues when we share our git repository with others or any online platform in public mode like GitHub public repository.
So ignoring files and folders we need to create a file named .gitignore in the root directory of your repository. If you can not create dot file in your system use touch command or create from vs code or other code editor. You can create several .gitignore file for several directories. To ignore files open your .gitignore file. To ignore file you can write the file name one after another in a new line like:
We can also ignore complete directory by writing directory name with a slash like if we want to ignore node_moduels and vendor directory we can write like this
We can ignore all .log file at a time using * wild card like this
This will ignore all .log files
When you add and commit all files and directories will be ignored included in .gitignore file.
You can follow the gitignore.io website to get recommended .gitignore file for your project. Like if your project regarding with NodeJs go to the website and type node in the input field and click create button it will generate a .gitignore file for your project. You might not have all the ignored directory or file types but it would be good to use.
If you miss the previous content you can read it from here