Skip to content

Instantly share code, notes, and snippets.

@exaucae
Last active November 22, 2021 09:03
Show Gist options
  • Save exaucae/bd8d33207016586050d0e2bc65afa5bd to your computer and use it in GitHub Desktop.
Save exaucae/bd8d33207016586050d0e2bc65afa5bd to your computer and use it in GitHub Desktop.
average to advanced git commands
  1. Delete the relevant section from the .gitmodules file. 2.Stage the .gitmodules changes: git add .gitmodules
  2. Delete the relevant section from .git/config.
  3. Remove the submodule files from the working tree and index: git rm --cached path_to_submodule (no trailing slash).
  4. Remove the submodule's .git directory: rm -rf .git/modules/path_to_submodule
  5. Commit the changes: git commit -m "Removed submodule "
  6. Delete the now untracked submodule files: rm -rf path_to_submodule

Ref: https://stackoverflow.com/questions/1260748/how-do-i-remove-a-submodule

// Git cherry-pick in action
// initial state
commit1 - commit2 - **commitIWantToGet** - commit4 - commit5 - commit6 otherBranch
\
myComit1 - myCommit2 - myCommit3 - myCommit4 myBranch
> git checkout otherBranch
(otherBranch) > git log
commit aae7c0606e00b58fv2361d3646729bdbb37844bqs
Author: chrys-exaucet <chrysexaucet@hotmail.fr>
Date: Mon Aug 20 03:18:23 2021 +0000
...
...
commit ShaOfCommitIWantToGet
Author: chrys-exaucet <chrysexaucet@hotmail.fr>
Date: Sun Aug 29 01:08:39 2021 +0000
...
...
(otherBranch) > git checkout myBranch
(myBranch) > git cherry-pick ShaOfCommitIWantToGet
// new state
commit1 - commit2 - commitIWantToGet - commit4 - commit5 - commit6 otherBranch
\
myComit1 - myCommit2 - myCommit3 - myCommit4 - **commitIWantToGet** myBranch
# squashing your laast n commits
# this operation combines your last n commits into a single one
# >>>> here is the syntax
git reset --soft HEAD~<n> && git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"
# or just use <<<<<
git rebase -i HEAD~<n>
# if so, follow the vim interactive editor that will show up
# pay attention to the commands given
# deleting a local branch
git branch -d <your-branch>
# to relfect the change son the remote branch use this
git push origin --delete <your-remote-branch>
# Download gitlab-cli
npm install git-lab-cli -g
# use this to send merge requests
lab merge-request -b <repo/your-base-branch> -t <your-target-branch>
Flow to reorder commit history.
___
reset without loosing changes
1. git reset --soft:
save
2. git stash
reset to current to your target branch
3. git reset --hard origin/<target_branch>
unstash changes from step 2
4 git stash pop

VCS Semantic commits for meaningful messages

format

(type)(portional scope)(optional issue): (short summary)

Types

Related to SemVer

  • feat <---> MINOR : A new feature useful for endusers
  • fix <---> PATCH : bug fix for endusers (not a build-process fix)
  • BREACKING CHANGE <---> MAJOR

Not related to SemVer

  • chore: A code change that external user won't see (eg: change to .gitignore file or .prettierrc file)
  • build: Build related changes (eg: npm related/ adding external dependencies)
  • test: dding new test or making changes to existing test
  • docs: Documentation related changes
  • refactor: refactoring of code
  • style: update code formatting (indentation, tabs vs spaces, etc.). For style updates that would effect the enduser, such as CSS changes, use the feat: tag instead.
  • perf: code that improves performance
  • ci
  • revert
  • lang: changes in i18n
  • localize:changes in l10n

Summary

In imperative and present tense. Not capitalized. No period at the end Use "add" instead of "added" or "adds"

Extras

!: to draw attention to breacking change

Examples

  • chore: add gradle build script
  • chore: update build script to webpack 4
  • docs: explain hat wobble
  • feat: add user login
  • fix: remove broken confirmation message
  • feat(lang): add polish language
  • refactor: share logic between 4d3d3d3 and flarhgunnstow
  • refactor!: drop support for Node 6
  • style: convert tabs to spaces
  • test: add assertions for Collection update and destroy methods

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment