Skip to content

Instantly share code, notes, and snippets.

@saurabhj
Last active December 4, 2019 11:22
Show Gist options
  • Select an option

  • Save saurabhj/5f61ec198ec104f3f86f195c2ca993d0 to your computer and use it in GitHub Desktop.

Select an option

Save saurabhj/5f61ec198ec104f3f86f195c2ca993d0 to your computer and use it in GitHub Desktop.

Revisions

  1. saurabhj revised this gist Dec 4, 2019. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion git_commands.md
    Original file line number Diff line number Diff line change
    @@ -25,4 +25,12 @@ git reset --hard <last_known_good_commit>
    # optional
    ```

    ---
    ---

    I have just made a commit (not pushed online) - but I want to uncommit it - because either I need to add more files or I committed it to the wrong branch.

    ```
    git reset --soft HEAD^
    ```

    More info: https://stackoverflow.com/questions/2845731/how-to-uncommit-my-last-commit-in-git
  2. saurabhj revised this gist Jul 11, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion git_commands.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    Match local branch to online repo
    Get your local branch to match the online repository
    i.e. online repo -> local
    ```
    git fetch origin
    git reset --hard origin/master
  3. saurabhj revised this gist Jan 31, 2019. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions git_commands.md
    Original file line number Diff line number Diff line change
    @@ -24,6 +24,4 @@ git reset --hard <last_known_good_commit>
    # optional
    ```

    ---

    (Undo stuff that has not been pushed)
    ---
  4. saurabhj created this gist Jan 31, 2019.
    29 changes: 29 additions & 0 deletions git_commands.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    Match local branch to online repo
    ```
    git fetch origin
    git reset --hard origin/master
    ```

    ---

    https://stackoverflow.com/a/36177806/7082
    (Undo stuff that has been already pushed)
    I have a project in a remote repository, synchronized with a local repository (development) and the server one (prod). I've been making some commited changes already pushed to remote and pulled from the server. Now, I want to undo those changes. So I could just git checkout to the commit before the changes and commit the new changes, but I'm guessing that there will be problems to push them again to remote. Any suggestion on how should I proceed?

    In the server, move the cursor back to the last known good commit:

    ```
    git push -f origin <last_known_good_commit>:<branch_name>
    ```

    Locally, do the same:

    ```
    git reset --hard <last_known_good_commit>
    # ^^^^^^
    # optional
    ```

    ---

    (Undo stuff that has not been pushed)