mibu
4/30/2017 - 10:13 AM

git

git

/*=============================================
=            Differance between            =
=============================================*/

# changed but not yet staged
git diff

#staged changes to your last commit
git diff --staged

# uncommited file to HEAD
git diff <path>

# uncommited file to before last commit
git diff HEAD^ -- <path>

#last commit to before last commit
git diff HEAD^ HEAD -- <path>

#difference between HEAD and n-th grandparent
git diff HEAD~n HEAD -- <path>

#Another cool feature is whatchanged command
git whatchanged -- <path>

/*-----  End of Differance between  ------*/

/*==========  GIT setup  ==========*/
$ git config --global user.name "Mikolaj Burawski"
$ git config --global user.email mikolaj.burawski@gmail.com

$ git config --global core.excludesfile ~/.gitignore_global

/*==========  GIT log  ==========*/
# the difference introduced in each commit. limit to 2 commmits
$ git log -p -2

# some abbreviated stats for each commit
git log --stat

#prints each commit on a single line
$ git log --pretty=oneline

#adds a nice little ASCII graph showing your branch and merge history
$ git log --pretty=format:"%h %s" --graph

#--since and --until are very useful
$ git log --since=2.weeks

# takes a string and only shows the commits that introduced a change to the code that added or removed that string.
$ git log -Sfunction_name

/*==========  Undo Things  ==========*/

#  takes your staging area and adds it to yu previos commit, if nothing was changed then you can change a message
$ git commit --amend

#unstaging a staged file
$ git reset HEAD <file>

#unmodifying a modified file. dangerous command!
$ git checkout -- <file>

/*==========  Working with Remotes  ==========*/

#show your remotes

$ git remote
$ git remote -v

#adding remote repositories

$ git remote add [shortname] [url]
$ git remote add pb https://github.com/paulboone/ticgit

#fetch all the information that Paul has but that you don’t yet have in your repository
#it doesn’t automatically merge it
$ git fetch pb

#to automatically fetch and then merge a remote branch
$git pull

#pushing to your remotes
$ git push [remote-name] [branch-name]
$ git push origin master

#If you didn’t want it to be called serverfix on the remote, you could push your local serverfix branch to the awesomebranch branch on the remote project.
$ git push origin serverfix:awesomebranch

#Don’t type your password every time.
git config --global credential.helper cache  --timeout <seconds> #the default is “900”, or 15 minutes

#Checkout remote Git branch. BETTER!
$ git fetch origin
$ git checkout -b serverfix origin/serverfix

#If you already have a local branch and want to set it to a remote branch you just pulled down, or want to change the upstream branch you’re tracking.
$ git branch -u origin/serverfix

#Deleting Remote Branches
$ git push origin --delete serverfix

#see what tracking branches you have set up.
$ git branch -vv

#to see more information about a particular remote
$ git remote show [remote-name]
$ git remote show origin

#renaming remotes
$ git remote rename pb paul

#remove remote
$ git remote rm paul

/*==========  Tagging  ==========*/
#list your tags
$ git tag

# search for tags with a particular pattern
$ git tag -l 'v1.8.5*'

#creating an annotated tag
$ git tag -a v1.4 -m 'my version 1.4'

#see the tag data along with the commit
$ git show v1.4

#lightweight tags
$ git tag v1.4-lw

#tagging later
git tag -a v1.2 9fceb02

#sharing tags
$ git push origin v1.5
$ git push origin --tags

/*==========  Git Aliases  ==========*/

$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.ci commit
$ git config --global alias.st status

# add your own unstage alias to Git
$ git config --global alias.unstage 'reset HEAD --'

#last commit
$ git config --global alias.last 'log -1 HEAD'

#print out the history of your commits, showing where your branch pointers are and how your history has diverged
$ git log --oneline --decorate --graph --all

/*==========  Branch Management  ==========*/
#list of branches
$ git branch

#to see the last commit on each branch
$ git branch -v

# can filter this list to branches that you have or have not yet merged into the branch you’re currently on.
$ git branch --merged
$ git branch --no-merged

/*==========  Rebasing  ==========*/

1a)	$ git checkout experiment
	$ git rebase master
#Check out the client branch, figure out the patches from the common ancestor of the client and server branches, and then replay them onto master.
1b) $ git rebase --onto master server client

1c) $ git rebase master server


#At this point, you can go back to the master branch and do a fast-forward merge.
2)	$ git checkout master
	$ git merge experiment

/*==========  Commit guidelines  ==========*/

#you don’t want to submit any whitespace errors.
git diff --check


/*==========  Push up an existing repository. Bitbucket  ==========*/
git remote add origin git@gitlab.com:maxymiser-us-team/omnihotels.com.git
git push -u origin --all


#Push existing branch out
$ git push -u origin feature_branch_name

#если бы ты после этого сделал в ветке module3-task2 
git rebase upstream/master

git rebase -i HEAD~2

#checkout pull request locally
git fetch origin pull/ID/head:BRANCHNAME