Skip to content

Instantly share code, notes, and snippets.

@janglapuk
Last active November 27, 2023 10:34
Show Gist options
  • Select an option

  • Save janglapuk/2e84fbc6faa5dda486ecdb2f45fccc23 to your computer and use it in GitHub Desktop.

Select an option

Save janglapuk/2e84fbc6faa5dda486ecdb2f45fccc23 to your computer and use it in GitHub Desktop.

Revisions

  1. janglapuk revised this gist Nov 27, 2023. 1 changed file with 10 additions and 2 deletions.
    12 changes: 10 additions & 2 deletions git-archive-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -5,8 +5,9 @@ git archive --output=archive.zip HEAD

    ## Archive HEAD with directory prefix (like github ZIP archive)
    ```bash
    git archive --output=archive.zip --prefix=main HEAD
    git archive --output=archive.zip --prefix=main/ HEAD
    ```
    Important: prefix should have a trailing slash

    ## Archive changes between two commits (bash)
    ```bash
    @@ -22,5 +23,12 @@ git archive --output=archive.zip HEAD -- $(Get-Content changes.txt)
    ## Archive HEAD with excluded file/directory from `.gitignore` (e.g. `.env`, `vendor`, `node_modules`, etc.)
    ```bash
    git archive --output=archive.zip HEAD
    7z a -r archive.zip vendor
    7z a archive.zip vendor
    ```

    If `--prefix` is set, then you need to rename (`7z rn`) the directory to place inside prefix directory
    ```bash
    git archive --output=archive.zip --prefix=main/ HEAD
    7z a archive.zip vendor
    7z rn archive.zip vendor main/vendor
    ```
  2. janglapuk revised this gist Nov 27, 2023. 2 changed files with 26 additions and 16 deletions.
    16 changes: 0 additions & 16 deletions git-archive-cheatsheet
    Original file line number Diff line number Diff line change
    @@ -1,16 +0,0 @@
    # archive HEAD
    git archive --output=archive.zip HEAD

    # archive HEAD with directory prefix (like github ZIP archive)
    git archive --output=archive.zip --prefix=main HEAD

    # archive changes between two commits (bash)
    git archive --output=archive.zip HEAD $(git diff --name-only commit_ID_A commit_ID_B)

    # archive changes between two commits (PowerShell)
    git diff --name-only commit_ID_A commit_ID_B | Out-File -Encoding ASCII changes.txt
    git archive --output=archive.zip HEAD -- $(Get-Content changes.txt)

    # archive HEAD with excluded file/directory from .gitignore (e.g. .env, vendor, node_modules, etc.)
    git archive --output=archive.zip HEAD
    7z a -r archive.zip vendor
    26 changes: 26 additions & 0 deletions git-archive-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    ## Archive HEAD
    ```bash
    git archive --output=archive.zip HEAD
    ```

    ## Archive HEAD with directory prefix (like github ZIP archive)
    ```bash
    git archive --output=archive.zip --prefix=main HEAD
    ```

    ## Archive changes between two commits (bash)
    ```bash
    git archive --output=archive.zip HEAD $(git diff --name-only commit_ID_A commit_ID_B)
    ```

    ## Archive changes between two commits (PowerShell)
    ```powershell
    git diff --name-only commit_ID_A commit_ID_B | Out-File -Encoding ASCII changes.txt
    git archive --output=archive.zip HEAD -- $(Get-Content changes.txt)
    ```

    ## Archive HEAD with excluded file/directory from `.gitignore` (e.g. `.env`, `vendor`, `node_modules`, etc.)
    ```bash
    git archive --output=archive.zip HEAD
    7z a -r archive.zip vendor
    ```
  3. janglapuk created this gist Nov 27, 2023.
    16 changes: 16 additions & 0 deletions git-archive-cheatsheet
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    # archive HEAD
    git archive --output=archive.zip HEAD

    # archive HEAD with directory prefix (like github ZIP archive)
    git archive --output=archive.zip --prefix=main HEAD

    # archive changes between two commits (bash)
    git archive --output=archive.zip HEAD $(git diff --name-only commit_ID_A commit_ID_B)

    # archive changes between two commits (PowerShell)
    git diff --name-only commit_ID_A commit_ID_B | Out-File -Encoding ASCII changes.txt
    git archive --output=archive.zip HEAD -- $(Get-Content changes.txt)

    # archive HEAD with excluded file/directory from .gitignore (e.g. .env, vendor, node_modules, etc.)
    git archive --output=archive.zip HEAD
    7z a -r archive.zip vendor