![]() Note the changes this commit introduced using git diff. Start by adding the changes introduced in “Commit 3” to feature_branch. The commit which feature_branch is pointing to.The commit which “Commit 3” is pointing to.There are technically a few changes between the current “gitsaster” state and the desired state: Similar to that instance, we now want the change introduced in this commit on an already existing branch.Ī reminder, it’s useful to draw the current state versus the desired state. Oh, wait! What if you actually wanted this change to be introduced in the feature_branch, and not in main? We dealt with a similar case where we accidentally committed to the main branch, but actually wanted the commit to be recorded on a new branch. ![]() Now, switch back to the main branch using git checkout, make changes to the file 1.txt, and record these changes on main branch: Next, create a new file, and commit this addition to this feature branch. Committing to the wrong branchĪs I explained in the post about creating a repository from scratch, this creates the branch feature_branch, and also changes HEAD to point to that branch. This commit was added to the main branch, as we can verify using git log. I then added it to the index, and created a commit. To get started, let’s start by creating a small repository to play with.Īs you can see, I’ve created a repository and created a file called 1.txt, with the content hello. In this post, you’ll acquire additional tools to rewrite history and deal with “gitsasters.” Be sure to read Part 1 first, so you have the relevant background for overcoming git disasters. We then applied our knowledge to a few “gitsasters,” and saw that by understanding git and how it works, we can feel confident fixing cases when we need to rewrite history. You can set rule at phpcs.In the previous post in this series, we learned about the command git reset, together with its three modes – -soft, -mixed, and -hard. PHP Code Beautifier and Fixer php vendor/bin/phpcbf -standard=PSR2 Php vendor/bin/phpcs -standard=phpcs.xml Install with composer composer require "squizlabs/php_codesniffer=*" vendor/bin/phpcs -standard="$RULESET" "$FILE" ![]() Using Git hook pre-commit we can restrict developers to commit code without PSR2 standard code at the time of commit any changes.Ĭode Snippets STAGED_FILES=$(git diff -cached -name-only -diff-filter=ACM | grep ".php\$") # Multiple git functions with single command # removes untracked files from the working directory Git stash list / git stash show stash apply stash pop (LIFO) = git stash apply + git stash drop # save uncommitted changes locally, switch branches to work on other parts # Create patch file and applying that rollback to any previous point/head # Showing log, commit, branch information # Hard reset if rollback to any previous point/head # if only the commit message gets changes or destroyed, it's acceptable Git commit -m “initial commit” / git commit -am “initial commit” # after resolving the conflicts if any occurs # and the local working tree which is not always desirable # will remove the file from both the index/stage # to discard/revert changes in working directory # to view changes in working directory, press q to exit from diff screen # create a new branch with current branch code and checkout on that A few of the git commands including basics and advance are listed below # initial setup Git (most of us know to some extent), is a freely available, distributed and decentralized version control system that helps developers to collaborate with multiple people on their projects and makes their life easy. #git #gitbash #gitcommand #github #githook GitHub
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |