Git
Frequently used git snippets
Commands
git add <file>
Add new file to stage area
git diff
Check changes on repo
Terms
HEAD
Reference to the last commit
Check last commits
git log
Adding empty folder to git
Create a .gitignore
at the root of such folder and place the following content there:
Situations
When going from develop to master tagged with release number
When creating new features branch from develop
git checkout -b [name_of_your_new_branch] develop
Then, normally finishing with:
git push origin [name_of_your_new_branch]
Merging back to develop:
note:
--no-ff
create new commit with the merge
When creating a release (branch for last minutes fixes for release from develop )
git checkout -b release-[version] develop
Finishing with release branch
git checkout master
git merge --no-ff release-[version]
git tag -a [version]
and then to develop
git checkout develop
git merge --no-ff release-[version]
finally
git branch -d release-[version]
Fixing production issues:
git checkout -b hotfix-[version+0.0.1] master
3 or release branch
git commit -m 'Fixing severe bug'
git checkout master
git merge --no-ff hotfix-[version+0.0.1]
git branch -d hotfix-[version+0.0.1]
Rename branch
git checkout <old_name>
git branch -m <new_name>
git push origin --delete <old_name>
git push origin -u <new_name>
Check changes
Undo commits
Remove files from Git commit
I think other answers here are wrong, because this is a question of moving the mistakenly committed files back to the staging area from the previous commit, without cancelling the changes done to them. This can be done like Paritosh Singh suggested:
or
Then reset the unwanted files in order to leave them out from the commit:
Now commit again, you can even re-use the same commit message:
Git global setup
Create a new repository
Push an existing folder
Push an existing Git repository
git ignore
Fix undesired push files
Replace the example commit
04833737604b1bf98ed65cf940eb79ff069771ff
with the commit you want to revert to. This should be the commit right before you committed the secrets. This will revert all the commits up to the commit you specified, while keeping all your changes staged in localUnstages all the changes you just reset
Add the files you want to the commit
Commit your changes
Force your new local repo changes to overwrite the remote repo, effectively getting rid of the secrets you accidentally committed
Commit specific changes of a file
Remove a file to not check its update going forward
More info on this stackoverflow
Commits
Try to keep the convention:
bug fix, a feature, change to the documentation, etc. as prefix to subject (fix, feat, doc).
Some guidelines
For example, your commit message should start with one of the following words:
feat: a new feature
fix: a bug fix
docs: changes to documentation
style: formatting, missing semi colons, etc; no code change
refactor: * refactoring production code
test: adding tests, refactoring test; no production code change
chore: updating build tasks, package manager configs, etc; no production code change
Also, subjects should be no greater than 50 characters and should begin with a capital letter and do not end with a period.
References
Last updated