Console tools & git
Console tools
Processes
Checking a PID of a process working on a TCP port (e.g. 9000)
$ lsof -i tcp:9000
Listing processes with a specific name (e.g. node)
ps aux
lists processes, grep
filters output.
$ ps aux | grep node
Killing a process with a specific PID (e.g. 3342)
The flag -9 means that the process won't get any notification what effects it can lose data.
$ kill -9 3342
Killing all processes with a specific name (e.g. node)
$ killall node
SASS
Converting a CSS file to a SASS file
$ sudo sass-convert --from css --to sass src/css/theme.css > src/sass/theme.sass
Git
Configuring git
$ git config --global user.name "<USERNAME>"
# example: git config --global user.name "Noman ur Rehman"
$ git config --global user.email "<EMAIL>"
# example: git config --global user.email "me@example.com"
$ git config --global push.default "simple"
# sets the simple push strategy which pushes
# from local branch(of the same name) to
# the remote branch(of the same name)
$ git config --global core.editor "<EDITOR_PATH>"
# example: git config --global core.editor "/Volumes/Media/Applications/Sublime\\ Text.app/Contents/SharedSupport/bin/subl"
Źródło
Conflicts in git
Stackoverflow: How to resolve merge conflicts in Git?
# config for <<<<<<<
$ git config merge.conflictstyle diff3
# search for conflicts
$ git diff --name-only --diff-filter=U
$ git grep '<<<<<<< HEAD'
# gui for conflicts
$ git mergetool
# show the conflicts
$ git diff
History and visual git
# checking changes on file named filename
$ git blame <filename>
# checking two last comits
$ git log -p -2
Program gitk
, tig
(konsolowy) lub GitKraken
.
Branch, merge, pulling and fetching
# show branch
$ git branch
# switch to development branch
$ git checkout development
# create development branch locally and switch to it
$ git checkout -b development
# only create development branch locally
$ git branch -b development
# rename local branch
$ git branch -m development dev
# create remote branch named 'home-security-system'
# and push local branch 'motion-detector' to it
$ git push origin motion-detector:home-security-system
# set upstream for local branch 'home-security-system'
$ git branch --set-upstream-to=origin/home-security-system home-security-system
$ git branch -u origin/home-security-system home-security-system
# switches to master branch
$ git checkout master
# merges dev into master
$ git merge dev
# only download changes from remote without merging locally
# http://stackoverflow.com/questions/292357/$difference-between-git-pull-and-git-fetch
$ git fetch
# download changes from remote with merging locally (deleting local changes)
# http://stackoverflow.com/questions/292357/difference-between-git-pull-and-git-fetch
$ git pull # but be sure to to add/commit/stash any work-in-progress first!
$ git fetch; git reset --hard origin/master # similar to git pull
Źródło
Zmiany w poprzednich wersjach i git rebase
More details about git rebase
. Difference between merge and rebase.
$ git checkout COMMIT_TAG
# where COMMIT_TAG is id of commit or tag, ie. v0.7.0 or 6e685f0
$ git checkout -b NEW/BRANCHNAME
$ git add . && git commit -m "Changes" && git push
# Now it looks like:
#
# A---B---C topic
# /
# D---E---F---G master
# After command `git rebase master` or `git rebase master topic` it will look like:
#
# A'--B'--C' topic
# /
# D---E---F---G master
# Then use
$ git pull
Deleting not committed files forever
$ git clean -i
Przywracanie i resetowanie zmian
Wycofywanie dowolnego commita
git revert
tworzy nowy commit, który jest przeciwieństwem oznaczonego danym SHA - wycofuje wszystkie zmiany, jakie były wprowadzone w danym commicie (wycofuje tylko dany commit, nie wszystkie następujące po nim).
$ git revert <SHA>
Zmiana komentarza ostatniego commita
W przypadku popełnienia błędu w komentarzu do ostatniego commita, można go zmienić za pomocą poniższych komend, które po prostu wprowadzają dokładnie takie same zmiany jak dany commit.
$ git commit --amend
$ git commit --amend -m "Fixes bug #42"
Przywracanie zresetowanych commitów
Poniższa komenda służy do przywrócenia commitów, które zostały pominięte np. za pomocą git reset
. Zapamiętuje tylko te stany, które są możliwe do przywrócenia.
$ git reflog
If you want to restore the project's history as it was at that moment in time use
$ git reset --hard <SHA>
If you want to recreate one or more files in your working directory as they were at that moment in time, without altering history use
$ git checkout <SHA> -- <filename>
If you want to replay exactly one of those commits into your repository use
$ git cherry-pick <SHA>
Resetowanie repozytorium do dowolnego commita
Uwaga! Nie spushowane commity zostaną prawdopodobnie utracone.
$ git reset --hard <last good SHA>
Cofanie zmian na wybranym pliku
Poniższa komenda usuwa wszelkie zmiany na pliku filename
od czasu ostatniego commita. Zmiany są bezpowrotnie utracone, ponieważ nie były wcześniej commitowane.
$ git checkout -- <filename>
Cofanie i usuwanie wszystkich zmian (ale nie spushowanych)
$ git add newfile.js
$ git commit ...
$ git reset --hard HEAD~1
# HEAD won't have last commit and newfile.js will be deleted
Cofanie dodanych zmian
$ git add newfile.js
$ git reset
# newfile.js will be unstaged
Cofanie scommitowanych (ale nie spushowanych) zmian
$ git add newfile.js
$ git commit ...
$ git reset HEAD~1
# newfile.js will be unstaged
Cofanie i usuwanie wszystkich zmian
git add newfile.js
git commit ...
git reset --hard HEAD~1
# HEAD won't have last commit
Cofanie dodanych zmian
git add newfile.js
git reset
# newfile.js will be unstaged
Tagowanie
# lista tagow
$ git tag
# wyszukiwanie tagow
$ git tag -l 'v1.4.2.*'
# tworzenie taga z opisem
$ git tag -a v1.4 -m 'my version 1.4'
# pokazywanie szczegolow tagow
$ git show
# pushowanie tagow
$ git push origin v1.5
$ git push origin <TAGNAME>
$ git push origin --tags
# pullowanie tagow
$ git fetch --tags
# zmiana wersji na tag
$ git checkout tags/<TAGNAME>
Dodawanie repozytorium do istniejącego folderu
$ git init
$ git remote add origin <PATH_TO_REPO>
$ git fetch
$ git checkout -t origin/master
# pulls master from added remote
$ git pull <REPONAME> master
# example: git pull rebelidealist master
Źródło
Pushowanie projektu do innego repozytorium
$ git remote add origin <PATH/TO/REPO>
$ git push -u origin/master
Źródło