Skip to content

Instantly share code, notes, and snippets.

@abbas-v1
Last active December 2, 2023 09:33
Show Gist options
  • Select an option

  • Save abbas-v1/bfc9dcc7ab352b496cd2a4816b501811 to your computer and use it in GitHub Desktop.

Select an option

Save abbas-v1/bfc9dcc7ab352b496cd2a4816b501811 to your computer and use it in GitHub Desktop.

Revisions

  1. Abbas Muhammad revised this gist Dec 2, 2023. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion git-commands
    Original file line number Diff line number Diff line change
    @@ -128,6 +128,11 @@ git fetch --all
    Then is possible to merge another branch from the new remote to your current one.
    git merge template/main --allow-unrelated-histories

    Rebase your branch to current master branch
    Rebase your branch to master branch
    git rebase master
    git push --force origin your_branch_name

    If you have a branch A from master and then another branch B from A and want to connect B to master
    git checkout B
    git rebase A --onto master
    git push --force origin B
  2. Abbas Muhammad revised this gist Jul 28, 2023. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion git-commands
    Original file line number Diff line number Diff line change
    @@ -126,4 +126,8 @@ Then run git fetch to update the changes
    git fetch --all

    Then is possible to merge another branch from the new remote to your current one.
    git merge template/main --allow-unrelated-histories
    git merge template/main --allow-unrelated-histories

    Rebase your branch to current master branch
    git rebase master
    git push --force origin your_branch_name
  3. abbas-v1 revised this gist Apr 1, 2022. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion git-commands
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,7 @@ git branch -a

    List all tags
    ```

    git tag -l
    ```

    @@ -114,4 +115,15 @@ for commit in $(git log --reverse --pretty=%H --since="2021-05-27T17:19:00" --un
    do
    git cherry-pick $commit
    done
    ```
    ```

    Get changes from GitHub template

    On the other repositories you have to add this template repository as a remote.
    git remote add template https://github.com/bit-oasis/template-service.git

    Then run git fetch to update the changes
    git fetch --all

    Then is possible to merge another branch from the new remote to your current one.
    git merge template/main --allow-unrelated-histories
  4. abbas-v1 revised this gist May 30, 2021. No changes.
  5. abbas-v1 revised this gist May 30, 2021. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions git-commands
    Original file line number Diff line number Diff line change
    @@ -106,4 +106,12 @@ git clean -f -d
    Files changed in this branch
    ```
    git diff master.. --name-only
    ```

    Cherry-pick commits from one branch into another
    ```
    for commit in $(git log --reverse --pretty=%H --since="2021-05-27T17:19:00" --until="2021-05-30T12:03:00" --all);
    do
    git cherry-pick $commit
    done
    ```
  6. abbas-v1 revised this gist Sep 18, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions git-commands
    Original file line number Diff line number Diff line change
    @@ -92,13 +92,13 @@ Reset local branch to previous commit
    git reset --hard e3f1e37
    ```

    Reset remote branch to previous commit
    Hard reset remote branch to previous commit
    ```
    git reset --hard e3f1e37
    git push --force origin develop
    ```

    Reset to clean untracked files and directories
    Hard reset to clean untracked files and directories
    ```
    git clean -f -d
    ```
  7. abbas-v1 revised this gist Sep 18, 2019. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions git-commands
    Original file line number Diff line number Diff line change
    @@ -87,6 +87,17 @@ Completely undo it, throwing away all uncommitted changes, resetting everything
    git reset --hard HEAD^
    ```

    Reset local branch to previous commit
    ```
    git reset --hard e3f1e37
    ```

    Reset remote branch to previous commit
    ```
    git reset --hard e3f1e37
    git push --force origin develop
    ```

    Reset to clean untracked files and directories
    ```
    git clean -f -d
  8. abbas-v1 renamed this gist May 8, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  9. abbas-v1 revised this gist Feb 25, 2019. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions git-commands.md
    Original file line number Diff line number Diff line change
    @@ -87,6 +87,11 @@ Completely undo it, throwing away all uncommitted changes, resetting everything
    git reset --hard HEAD^
    ```

    Reset to clean untracked files and directories
    ```
    git clean -f -d
    ```

    Files changed in this branch
    ```
    git diff master.. --name-only
  10. abbas-v1 revised this gist Feb 25, 2019. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions git-commands.md
    Original file line number Diff line number Diff line change
    @@ -85,4 +85,9 @@ git reset HEAD^
    Completely undo it, throwing away all uncommitted changes, resetting everything to the previous commit
    ```
    git reset --hard HEAD^
    ```

    Files changed in this branch
    ```
    git diff master.. --name-only
    ```
  11. abbas-v1 revised this gist Feb 25, 2019. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion git-commands.md
    Original file line number Diff line number Diff line change
    @@ -18,11 +18,13 @@ List all tags
    git tag -l
    ```

    Checkout a specific branch, tag or revision
    Checkout a specific branch, tag, revision, file or a directory
    ```
    git checkout <branch_name>
    git checkout tags/<tag_name>
    git checkout <revision_sha>
    git checkout origin/master -- <filename>
    git checkout origin/master -- </directory/path/>
    ```

    Stashing changes
  12. abbas-v1 revised this gist May 4, 2017. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions git-commands.md
    Original file line number Diff line number Diff line change
    @@ -58,6 +58,18 @@ Resolve merge conflicts
    git mergetool
    ```

    If already in conflict state, and want to accept all of theirs
    ```
    git checkout --theirs .
    git add .
    ```

    If already in conflict state, and want to accept all of ours
    ```
    git checkout --ours .
    git add .
    ```

    Undo the act of committing, leaving everything else intact
    ```
    git reset --soft HEAD^
  13. abbas-v1 revised this gist Oct 15, 2016. 1 changed file with 0 additions and 5 deletions.
    5 changes: 0 additions & 5 deletions git-commands.md
    Original file line number Diff line number Diff line change
    @@ -71,9 +71,4 @@ git reset HEAD^
    Completely undo it, throwing away all uncommitted changes, resetting everything to the previous commit
    ```
    git reset --hard HEAD^
    ```

    SVN difference
    ```
    svn diff -r 13:17 > review.patch
    ```
  14. abbas-v1 revised this gist Oct 15, 2016. 1 changed file with 30 additions and 32 deletions.
    62 changes: 30 additions & 32 deletions git-commands.md
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,8 @@
    # gitCommands

    Go to the directory **where** you want to clone the repo
    ```
    git clone repository_URL
    ```

    To ignore a tracked file
    Clone a remote repository on your local machine
    ```
    git update-index --assume-unchanged <file>
    git clone <repository_url>
    ```

    To start tracking changes again
    ```
    git update-index --no-assume-unchanged <file>
    ```

    To revert changes made in a previous commit
    ```
    git revert dd61ab32
    ```
    note: for a small message [ -m "sldfkjs dflskdifs" ]

    List all local branches
    ```
    git branch
    @@ -40,37 +22,53 @@ Checkout a specific branch, tag or revision
    ```
    git checkout <branch_name>
    git checkout tags/<tag_name>
    git checkout <sha_of_revision>
    git checkout <revision_sha>
    ```

    Show the change history of a file
    Stashing changes
    ```
    gitk [fileNamWithPath]
    git stash list
    git stash
    git stash pop
    git stash drop
    ```

    To merge conflicts. Commit your local changes without pushing and git a pull. Then
    Ignore changes in a file that is currently being tracked
    ```
    git mergetool
    git update-index --assume-unchanged <file_name>
    ```

    Stashing changes
    Start tracking changes in a file that has been previously ignored
    ```
    git stash list
    git stash
    git stash pop
    git update-index --no-assume-unchanged <filen_name>
    ```

    Revert changes made in a previous commit
    ```
    git revert <revision_sha>
    ```

    Show change history of a file
    ```
    gitk <file_path>
    ```

    Resolve merge conflicts
    ```
    git mergetool
    ```

    If all you want to do is undo the act of committing, leaving everything else intact, use:
    Undo the act of committing, leaving everything else intact
    ```
    git reset --soft HEAD^
    ```

    If you want to undo the act of committing and everything you'd staged, but leave the work tree (your files intact):
    Undo the act of committing and everything you'd staged, but leave the work tree (your files intact)
    ```
    git reset HEAD^
    ```

    If you actually want to completely undo it, throwing away all uncommitted changes, resetting everything to the previous commit (as the original question asked):
    Completely undo it, throwing away all uncommitted changes, resetting everything to the previous commit
    ```
    git reset --hard HEAD^
    ```
  15. abbas-v1 revised this gist Oct 15, 2016. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion sdf.txt
    Original file line number Diff line number Diff line change
    @@ -1 +0,0 @@
    I like it **this** way.
  16. abbas-v1 renamed this gist Oct 15, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  17. abbas-v1 revised this gist Oct 15, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions sdf.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    I like it **this** way.
  18. abbas-v1 revised this gist Oct 15, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions git-commands
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    # gitCommands

    Go to the directory where you want to clone the repo
    Go to the directory **where** you want to clone the repo
    ```
    'git **clone** repository_URL'
    git clone repository_URL
    ```

    To ignore a tracked file
  19. abbas-v1 revised this gist Oct 15, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-commands
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    Go to the directory where you want to clone the repo
    ```
    'git clone repository_URL'
    'git **clone** repository_URL'
    ```

    To ignore a tracked file
  20. abbas-v1 revised this gist Oct 15, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-commands
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    Go to the directory where you want to clone the repo
    ```
    git clone repository_URL
    'git clone repository_URL'
    ```

    To ignore a tracked file
  21. abbas-v1 revised this gist Oct 15, 2016. No changes.
  22. abbas-v1 created this gist Oct 15, 2016.
    81 changes: 81 additions & 0 deletions git-commands
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,81 @@
    # gitCommands

    Go to the directory where you want to clone the repo
    ```
    git clone repository_URL
    ```

    To ignore a tracked file
    ```
    git update-index --assume-unchanged <file>
    ```

    To start tracking changes again
    ```
    git update-index --no-assume-unchanged <file>
    ```

    To revert changes made in a previous commit
    ```
    git revert dd61ab32
    ```
    note: for a small message [ -m "sldfkjs dflskdifs" ]

    List all local branches
    ```
    git branch
    ```

    List all local and remote branches
    ```
    git branch -a
    ```

    List all tags
    ```
    git tag -l
    ```

    Checkout a specific branch, tag or revision
    ```
    git checkout <branch_name>
    git checkout tags/<tag_name>
    git checkout <sha_of_revision>
    ```

    Show the change history of a file
    ```
    gitk [fileNamWithPath]
    ```

    To merge conflicts. Commit your local changes without pushing and git a pull. Then
    ```
    git mergetool
    ```

    Stashing changes
    ```
    git stash list
    git stash
    git stash pop
    ```

    If all you want to do is undo the act of committing, leaving everything else intact, use:
    ```
    git reset --soft HEAD^
    ```

    If you want to undo the act of committing and everything you'd staged, but leave the work tree (your files intact):
    ```
    git reset HEAD^
    ```

    If you actually want to completely undo it, throwing away all uncommitted changes, resetting everything to the previous commit (as the original question asked):
    ```
    git reset --hard HEAD^
    ```

    SVN difference
    ```
    svn diff -r 13:17 > review.patch
    ```