- Create a Docker image:
docker build -t my-tag .
-t my-tag
Give your image a tag "my-tag"
- Revert last commit but keep changes:
git reset --soft HEAD~1
- Revert all changes:
git reset --hard
- Create and switch to new branch but keep changes:
git checkout -b new_branch
-
Switch branch from a branch that has changes:
git checkout -f
revert any non-commit change -
Update your branch with remote branch, e.g. master:
git reset --hard origin/master
orgit stash
if you want to save your changesgit pull
The branch you're currently working on is referred to as HEAD
. Git highlights merge conflicts in the source code by tagging the pulled commit with a commit hash, while the branch you're working on is identified as HEAD.
Step 1. Fetch and check out this merge request's feature branch:
git fetch origin
git checkout -b 'uiwi-ads-form' 'origin/uiwi-ads-form'
Step 2. Review the changes locally. Step 3. Merge the feature branch into the target branch and fix any conflicts. How do I fix them?
git fetch origin
git checkout 'dev'
git merge --no-ff 'uiwi-ads-form'
Step 4. Push the target branch up to GitLab.
git push origin 'dev'
(master) git pull origin master
or(master) git fetch --all --tags
(my-branch) git rebase -i master
(my-branch) git checkout master
(master) git merge income_quiz
(master) git push
or(master) git push --force-with-lease
-
Update local repository to match origin repository: It updates all branches according to the origin, also removing those not found in the latter.
git fetch --all --prune
-
Remove all local branches not found in origin:
git branch --v | grep "\[gone\]" | awk '{print $1}' | xargs git branch -D
Source: https://stackoverflow.com/a/59228595 -
Rewrite history by squashing the latest N commits:
git reset --soft HEAD~N && git commit
Replace N with the number of the latest commits you want to squash. Source: https://stackoverflow.com/a/5201642 Or:git rebase -i --root
- this allows you to squash all commits saved on the branch- (interactive mode) Squash all commits you want to squash (squash works by merging to each previous commit; see snippet below)
- (interactive mode) Write an appropriate commit message for the squashed commits
All commits marked with "squash" are squashed with commit 066fb7a.
pick 5e96767 feat: CXO-1616 fix responsiveness, CXO-1617 implement feiertag theme
pick ad92bad refactor: CXO-1637 change minHeight to height for Quiz Widget
pick 066fb7a test: Enable logging to check payload
squash 16672eb refactor: Change variant declaration by fetching variant_name key
squash 562c394 refactor: Change api payload for test files
squash 0763c11 refactor: Fixed logic to correctly map variant
squash a49a84c fix: Fixed storybook not working after variantName change
pick d2e6b57 feat: CXO-1646 tiktok design
- Save multiple git stashes, and apply a particular stash. Stashes are saved in a queue: Index 0 has the newest stash, whereas any subsequent one is an older stash.
git stash list
- View all stashes.git stash clear
- Remove all stashes.git stash apply stash@{1}
- Apply particular stash. In this case, the second stash element from the beginning of the queue.
Example:
stash@{0}: WIP on master: 5be8c11 feat: CXO-1660
stash@{1}: WIP on CXO-1666_Krieg: 5be8c11 feat: CXO-1660
stash@{2}: WIP on CXO-1666_Krieg: ae049d7 feat: loki - Visual Regression Testing for Storybook
stash@{3}: WIP on master: 5d26463 refactor: logrocket disabled
stash@{4}: WIP on CXO-1640: 4b0fdbf Fix: Fixed storybook not working after variantName change
Show history
history
history -c
if you want to clear your history