Last active
March 16, 2020 10:11
-
-
Save akashnimare/e5b308a0df03c1ad3eb9752390fc49f4 to your computer and use it in GitHub Desktop.
Revisions
-
akashnimare revised this gist
Aug 31, 2018 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -134,4 +134,9 @@ git checkout username/branch This is pretty useful if you just want to exclude some files from git diff. ``` git diff -- . ':(exclude)*-lock.json' ``` # Show commits that have touched specific text in a file ``` git log -S "no-select" --stat -p -- path-of-the-file ``` -
akashnimare revised this gist
Jul 30, 2018 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -128,4 +128,10 @@ git stash clear git remote add username https://github.com/username/repo.git git fetch username branch git checkout username/branch ``` # Exclude files from git diff This is pretty useful if you just want to exclude some files from git diff. ``` git diff -- . ':(exclude)*-lock.json' ``` -
akashnimare revised this gist
Jul 9, 2018 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -120,4 +120,12 @@ git reset --soft HEAD~1 (changes to last commit will be available as uncommited # Delete all the git stash ``` git stash clear ``` # Checking someone's fork ``` git remote add username https://github.com/username/repo.git git fetch username branch git checkout username/branch ``` -
akashnimare revised this gist
Jun 19, 2018 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -115,4 +115,9 @@ git push origin push_from_branch:push_to_this_branch -f git reset --hard HEAD~1 (changes to last commit will be removed ) or git reset --soft HEAD~1 (changes to last commit will be available as uncommited local modifications) ``` # Delete all the git stash ``` git stash clear ``` -
akashnimare revised this gist
Jun 6, 2018 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -108,4 +108,11 @@ From branch1 git push origin branch1:branch2 -f or git push origin push_from_branch:push_to_this_branch -f ``` # Undoing a last commit ``` git reset --hard HEAD~1 (changes to last commit will be removed ) or git reset --soft HEAD~1 (changes to last commit will be available as uncommited local modifications) ``` -
akashnimare revised this gist
Jun 5, 2018 . 1 changed file with 10 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -99,4 +99,13 @@ function rmbranch() { git branch -D $1; } ``` then use it like `rmbranch dev`. # Push commit from one branch to another branch * So for an example if you want to push branch1 to branch2 then ``` From branch1 git push origin branch1:branch2 -f or git push origin push_from_branch:push_to_this_branch -f ``` -
akashnimare revised this gist
Dec 25, 2017 . 1 changed file with 17 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -83,3 +83,20 @@ git reset --hard FETCH_HEAD ``` hub checkout https://github.com/zulip/zulip-electron/pull/353 ``` # Delete a Git branch both locally and remotely? * remove a local branch from your machine: ``` git branch -d {the_local_branch} (use -D instead to force deleting the branch without checking merged status) ``` * To remove a remote branch from the server: ``` git push origin --delete {the_remote_branch} ``` * You can also make a function in your bashrc/zshrc: ``` function rmbranch() { git push origin --delete $1; git branch -D $1; } ``` then use it like `rmbranch dev`. -
akashnimare revised this gist
Dec 25, 2017 . 1 changed file with 5 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,14 +28,14 @@ git push --force # Cherry-pick a commit from another branch Git cherry-pick allows you to merge a single commit from one branch into another. To use the cherry-pick command follow these steps: * Check out the branch into which you want to merge the commit. (E.g.: `git checkout master`) * Identify the commit hash through your favorite method. You can use git log, a GUI tool such as sourcetree or tower, or if you use GitHub or BitBucket you can use their interface. In SWS we use GitHub, so I tend to use that method often. With GitHub you can find the commit hash on the commit list page or on the individual commit page itself. See the screenshots below. Pick'em! - ```git cherry-pick 9638d99c89a92350ad2f205f47af24b81ac39a64``` * If there is a merge conflict you will have to resolve that with your favorite merge tool, but otherwise you have now successfully pulled in the work from the other branch. # Squash All Commits Related to a Single Issue into a Single Commit If there are 5 commits in a PR and you want to squash them into one, follow this steps - * `git rebase -i HEAD~5` * In the text editor that comes up, replace the words "pick" with "squash" next to the commits you want to squash into the commit before it. * Save and close the editor * git will combine the "squash"'ed commits with the one before it. Git will then give you the opportunity to change your commit message. @@ -52,7 +52,8 @@ If there are 5 commits in a PR and you want to squash them into one, follow this # Checking a PR locally - There are couple of options to achieve this - * Save following function in your bashrc/zshrc and run `pullpr 123` ```sh function pullpr() { git fetch origin pull/$1/head:$1; @@ -78,7 +79,7 @@ git fetch "$remote" "pull/$request_id/head" git checkout -B "review-original-${request_id}" git reset --hard FETCH_HEAD ``` * Easiest way is to use [hub](https://github.com/github/hub) - ``` hub checkout https://github.com/zulip/zulip-electron/pull/353 ``` -
akashnimare revised this gist
Dec 25, 2017 . 1 changed file with 15 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -50,9 +50,17 @@ If there are 5 commits in a PR and you want to squash them into one, follow this * git push -f ``` # Checking a PR locally - There are couple of options to achieve this - * Save following function in your bashrc/zshrc and run pullpr 123 ```sh function pullpr() { git fetch origin pull/$1/head:$1; git checkout $1; } ``` * Run following bash script - ```sh #!/bin/bash set -e @@ -70,3 +78,7 @@ git fetch "$remote" "pull/$request_id/head" git checkout -B "review-original-${request_id}" git reset --hard FETCH_HEAD ``` * Easiest way is to use [hub](https://github.com/github/hub) ``` hub checkout https://github.com/zulip/zulip-electron/pull/353 ``` -
akashnimare revised this gist
Dec 25, 2017 . 1 changed file with 4 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -52,12 +52,11 @@ If there are 5 commits in a PR and you want to squash them into one, follow this # Checking a PR locally * Option 1: - Run following bash script ```sh #!/bin/bash set -e set -x if ! git diff-index --quiet HEAD; then set +x echo "There are uncommitted changes:" @@ -70,5 +69,4 @@ remote=${2:-"origin"} git fetch "$remote" "pull/$request_id/head" git checkout -B "review-original-${request_id}" git reset --hard FETCH_HEAD ``` -
akashnimare revised this gist
Dec 25, 2017 . 1 changed file with 23 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -49,3 +49,26 @@ If there are 5 commits in a PR and you want to squash them into one, follow this * Change the commit message * git push -f ``` # Checking a PR locally * Option 1: - Run following bash script ```sh #!/bin/bash set -e set -x if ! git diff-index --quiet HEAD; then set +x echo "There are uncommitted changes:" git status --short echo "Doing nothing to avoid losing your work." exit 1 fi request_id="$1" remote=${2:-"origin"} git fetch "$remote" "pull/$request_id/head" git checkout -B "review-original-${request_id}" git reset --hard FETCH_HEAD ``` -
akashnimare renamed this gist
Dec 23, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
akashnimare revised this gist
Dec 23, 2017 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,12 @@ # Reword a old commit message https://help.github.com/articles/changing-a-commit-message/ ``` * git checkout your-branch * git rebase -i HEAD~N (N is the number of commits) * use **reword** * Follow the steps * git push --force ``` # Update a PR with the upstream ``` -
akashnimare revised this gist
Dec 23, 2017 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,3 +40,10 @@ If there are 5 commits in a PR and you want to squash them into one, follow this * Use ```git show``` to check if everything is fine * If you've already pushed commits to GitHub, and then squash them locally, you will have to force the push to your branch. * ```git push -f or git push origin branch-name --force``` # Edit your last commit message - ``` * git commit --amend * Change the commit message * git push -f ``` -
akashnimare revised this gist
Dec 23, 2017 . 1 changed file with 11 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,4 +29,14 @@ Git cherry-pick allows you to merge a single commit from one branch into another * Check out the branch into which you want to merge the commit. (E.g.: git checkout master) * Identify the commit hash through your favorite method. You can use git log, a GUI tool such as sourcetree or tower, or if you use GitHub or BitBucket you can use their interface. In SWS we use GitHub, so I tend to use that method often. With GitHub you can find the commit hash on the commit list page or on the individual commit page itself. See the screenshots below. Pick'em! - ```git cherry-pick 9638d99c89a92350ad2f205f47af24b81ac39a64``` * If there is a merge conflict you will have to resolve that with your favorite merge tool, but otherwise you have now successfully pulled in the work from the other branch. # Squash All Commits Related to a Single Issue into a Single Commit If there are 5 commits in a PR and you want to squash them into one, follow this steps - * git rebase -i HEAD~5 * In the text editor that comes up, replace the words "pick" with "squash" next to the commits you want to squash into the commit before it. * Save and close the editor * git will combine the "squash"'ed commits with the one before it. Git will then give you the opportunity to change your commit message. * Use ```git show``` to check if everything is fine * If you've already pushed commits to GitHub, and then squash them locally, you will have to force the push to your branch. * ```git push -f or git push origin branch-name --force``` -
akashnimare revised this gist
Dec 23, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,5 +28,5 @@ git push --force Git cherry-pick allows you to merge a single commit from one branch into another. To use the cherry-pick command follow these steps: * Check out the branch into which you want to merge the commit. (E.g.: git checkout master) * Identify the commit hash through your favorite method. You can use git log, a GUI tool such as sourcetree or tower, or if you use GitHub or BitBucket you can use their interface. In SWS we use GitHub, so I tend to use that method often. With GitHub you can find the commit hash on the commit list page or on the individual commit page itself. See the screenshots below. Pick'em! - ```git cherry-pick 9638d99c89a92350ad2f205f47af24b81ac39a64``` * If there is a merge conflict you will have to resolve that with your favorite merge tool, but otherwise you have now successfully pulled in the work from the other branch. -
akashnimare revised this gist
Dec 23, 2017 . 1 changed file with 8 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,4 +22,11 @@ git rebase -i HEAD~N git fetch upstream git rebase upstream/master git push --force ``` # Cherry-pick a commit from another branch Git cherry-pick allows you to merge a single commit from one branch into another. To use the cherry-pick command follow these steps: * Check out the branch into which you want to merge the commit. (E.g.: git checkout master) * Identify the commit hash through your favorite method. You can use git log, a GUI tool such as sourcetree or tower, or if you use GitHub or BitBucket you can use their interface. In SWS we use GitHub, so I tend to use that method often. With GitHub you can find the commit hash on the commit list page or on the individual commit page itself. See the screenshots below. Pick'em! eg: ```git cherry-pick 9638d99c89a92350ad2f205f47af24b81ac39a64``` * If there is a merge conflict you will have to resolve that with your favorite merge tool, but otherwise you have now successfully pulled in the work from the other branch. -
akashnimare revised this gist
Dec 15, 2017 . 1 changed file with 18 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,3 +5,21 @@ https://help.github.com/articles/changing-a-commit-message/ * use **reword** * Follow the steps * git push --force # Update a PR with the upstream ``` git checkout master git fetch upstream git rebase upstream master git checkout <your-branch> git rebase -i master ``` # Update your fork repo with upstream ``` git checkout your-branch git rebase -i HEAD~N git fetch upstream git rebase upstream/master git push --force ``` -
akashnimare created this gist
Dec 15, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ # Reword a old commit message https://help.github.com/articles/changing-a-commit-message/ * git checkout your-branch * git rebase -i HEAD~N (N is the number of commits) * use **reword** * Follow the steps * git push --force