Git

Linux academy

Tags

I create a tag

git tag tag1

I see the tag list

git tag

I can create a file and commit

with this command I see the difference between the tag1 creation and now

git show tag1

I see the creation of the file

it show the tags and the commit reference

git describe --tags

Merge

show all branches

git branch -A

merge the development branch to its source branch (usually master)
—no-ff means we want to retain all the commit messages prior to the merge

git merge development --no-ff

Logs

see logs in pages

git log | more

-2 the last 2 logs
-p the difference introduced in every commit

git log -p -2

show statistics

git log --stat

the reference for each commit

git log --pretty=oneline

information about the author and the commit

git log --pretty=format:"%h: %an, %ae, %cn, %cd, - %s"

to see the branch and merge

git log --pretty=format:"%h: %an, %ae, %cn, %cd, - %s" --graph

gitlab

prerequisite

yum install postfix
systemctl enable postfix
systemctl start postfix
#disable o set to minimun the selinux
yum install httpd

Steps to create a client server git repository

follow this guide but commit something on the repo a text file with some letters
http://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server

Notes about the commands

undo the change

git checkout -f

other commands

git add .
git commit
git pull origin master
git push origin master

commit

git commit -m 'my comment here for not open the editor'

# this is to correct a previous comment of a commit before push 
git commit --amend

some commands

git init

git add '*.txt'

git log

git push -u origin master

The -u tells Git to remember the parameters, so that next time we can simply run git push

add a remote location

git remote add origin https://github.com/try-git/try_git.git

In this case we want the diff of our most recent commit, which we can refer to using the HEAD pointer.

git diff HEAD

this show the things commited but not yet pusched
git diff --staged

this reset the change
git reset octofamily/octodog.txt

undo the last changes, already commited or not yet commited BUT not pushed

git reset HEAD --hard

Commit in an empty repository

when you do a clone of an empy repository you obtain this

git clone ssh://git@myrepo:22/ops/vagrant-recipes
Cloning into 'vagrant-recipes'...
warning: You appear to have cloned an empty repository.

git add .
git commit -m 'comment is important'

git push 
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'ssh://git@myrepo22/ops/vagrant-recipes'

to resolve only the first commit you need to do
git push --set-upstream origin master

after you can commit normal

Analyze the git repos

install and run this command inside a git repository to do research ecc.

gitk

this open an interface to see the change from the commit the present

git difftool -y --dir-diff 831d9c78524d8a600cd18a2aa2c3369e0c636cc6

if you want to do with two different commit use the double ..

git difftool -y --dir-diff 831d9c78524d8a600cd18a2aa2c3369e0c636cc6..cc254b2337bfa01d459f28acfb2b88bc81ada7da

to use this tool you need to setup your ~/.gitconfig with this config

[merge]
        tool = git-meld
[diff]
        external = git-meld

and install meld

sudo aptitude install meld

undo the changes not commited

if you have your directory with some changes that you don't want add and you want to clean you need to to a stash

# git status
On branch master
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   auth.conf

no changes added to commit (use "git add" and/or "git commit -a")

# git stash
Saved working directory and index state WIP on master: 3728347 Merged in dev (pull request #2)
HEAD is now at 3728347 Merged in dev (pull request #2)

# git status
On branch master
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)

nothing to commit, working directory clean

# git pull origin master

BUT if you have new file you need to remove manually or use some others git commands , you can check with git status

Guide to study

The amazing interactive website to try git commands (HIGHLY recommended - All levels).
http://pcottle.github.io/learnGitBranching/

The post that started it all :)
http://nvie.com/posts/a-successful-git-branching-model/
http://nvie.com/files/Git-branching-model.pdf

Git internals video:
http://www.youtube.com/watch?v=JPakFGoM9KQ

Git flow wrapper script:
https://github.com/nvie/gitflow

Cheatsheet:
http://danielkummer.github.io/git-flow-cheatsheet/

GitHub 15 minutes interactive git tutorial (Beginners)
http://try.github.io/levels/1/challenges/1

Add-ons/Hacks:
Global git ignore:
- https://github.com/github/gitignore
Linux shell prompt + GIT:
- bash: https://github.com/magicmonty/bash-git-prompt
- bash: https://github.com/twolfson/sexy-bash-prompt
- fish: https://github.com/bpinto/oh-my-fish
- [Add your shell here]

Pretty neat and simple to understand submodules.
https://git.wiki.kernel.org/index.php/GitSubmoduleTutorial

Why should you consider to develop your project based on git submodules? This article explains perfectly why: https://blogs.atlassian.com/2013/03/git-submodules-workflows-tips/

Atlassian tutorial

https://www.atlassian.com/git/?utm_source=bitbucket&utm_medium=link&utm_campaign=homepage&utm_content=free_git_tutorials

Salvo diversa indicazione, il contenuto di questa pagina è sotto licenza Creative Commons Attribution-ShareAlike 3.0 License