AllanChain / blog

Blogging in GitHub issues. Building with Astro.
https://allanchain.github.io/blog/
MIT License
13 stars 0 forks source link

Git CheatSheet #154

Open AllanChain opened 3 years ago

AllanChain commented 3 years ago

View Post on Blog


Force pull

git fetch
git reset --hard origin/master

Assume unchanged

git update-index --assume-unchanged exam.ple

Upgrade git for windows

git update-git-for-windows

Delete tag

git tag -d tagname
git push --delete origin tagname

Remove submodule

From https://stackoverflow.com/a/1260982/8810271

  1. Delete the relevant section from the .gitmodules file.
  2. Stage the .gitmodules changes: git add .gitmodules
  3. Delete the relevant section from .git/config.
  4. Remove the submodule files from the working tree and index: git rm --cached path_to_submodule (no trailing slash).
  5. Remove the submodule's .git directory: rm -rf .git/modules/path_to_submodule
  6. Commit the changes: git commit -m "Removed submodule <name>"
  7. Delete the now untracked submodule files: rm -rf path_to_submodule

Split repo

Single File

From https://stackoverflow.com/questions/39479154/how-can-i-split-a-single-file-from-a-git-repo-into-a-new-repo Use git fast-export.

First, you export the history of the file to a fast-import stream. Make sure you do this on the master branch.

cd oldrepo
git fast-export HEAD -- MyFile.ext >../myfile.fi

Then you create a new repo and import.

cd ..
mkdir newrepo
cd newrepo
git init
git fast-import <../myfile.fi
git checkout

Sub Directory

git filter-branch -f --prune-empty --subdirectory-filter  path/to/module

How to make file +x in Git on Windows?

From https://stackoverflow.com/a/21694391/8810271

git update-index --chmod=+x foo.sh