Difference between revisions of "HowToGit"

From Lost In Wonderlands
Jump to: navigation, search
(setting p4v from perforce)
(git-merge)
Line 243: Line 243:
  
 
  git merge
 
  git merge
 +
 +
 +
==== resolving conflict with binary files ====
 +
* https://medium.com/@joshsaintjacque/resolving-merge-conflicts-in-binary-files-79df5aacd86f
 +
 +
If you want to take your changes over the ones you’re merging in, simply run:
 +
 +
  git checkout --ours -- path/to/file.binary
 +
 +
Inversely, if you want to take the merging changes over your own you can run
 +
 +
  git checkout --theirs -- path/to/file.binary
 +
 +
This works on non-binary files, too, but keep in mind it’s all-or-nothing. Either use all your changes to a file, or all theirs.
  
 
=== [https://git-scm.com/docs/git-rebase git-rebase] ===
 
=== [https://git-scm.com/docs/git-rebase git-rebase] ===

Revision as of 10:10, 9 October 2020

How To Git

NeXT Steps

 here everything has yet to be done !

coming soon :


Everything You Always Wanted to Know on git [seldom]... (But Were Afraid to Ask) a collection of links of interest

See also

useful commands

gitk
gitk --all

git apply

git apply path-to-apatch-file
see option --check and --stat

git-init

git init

git-clone

git clone git://github.com/foo/bar.git
git clone --recurse  git://github.com/foo/bar.git
git clone --recurse -j8 git://github.com/foo/bar.git
git clone --recurse-submodules git://github.com/foo/bar.git
git clone --recurse-submodules -j8 git://github.com/foo/bar.git

git-config

# git attitude git config (french)
git config --list
git config --list --show-origin
git config --global user.name "Your Name Comes Here"
git config --global user.email you@yourdomain.example.com
core.whitespace true
core.autocrlf true
core.safecrlf true
core.eol
core.symlinks false
core.whitespace true
   A comma separated list of common whitespace problems to notice. 
   git diff will use color.diff.whitespace to highlight them, and git apply --whitespace=error will consider them as errors. 
   You can prefix - to disable any of them (e.g. -trailing-space):
   blank-at-eol 
   treats trailing whitespaces at the end of the line as an error (enabled by default).
   space-before-tab 
   treats a space character that appears immediately before a tab character in the initial indent part of the line as an error (enabled by default).
   indent-with-non-tab 
   treats a line that is indented with space characters instead of the equivalent tabs as an error (not enabled by default).
   tab-in-indent 
   treats a tab character in the initial indent part of the line as an error (not enabled by default).
   blank-at-eof 
   treats blank lines added at the end of file as an error (enabled by default).
   trailing-space
   is a short-hand to cover both blank-at-eol and blank-at-eof.
   cr-at-eol 
   treats a carriage-return at the end of line as part of the line terminator, i.e. with it, trailing-space does not trigger 
   if the character before such a carriage-return is not a    whitespace (not enabled by default).
   tabwidth=<n> tells how many character positions a tab occupies; this is relevant for indent-with-non-tab and when Git fixes tab-in-indent errors. 
   The default tab width is 8. 
   Allowed values are 1 to 63.
# setting editor
#emacs
git config --global core.editor emacs
#vscode
#vi, vim
#nano
#TextEdit
# using notepad on window 64bits
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -nosession"
# using notepad on window 32 bits
git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -nosession"
# TextMate : l'invocation en ligne de commande mate doit être installée (ça se fait depuis Help > Terminal Usage… dans la v1 et depuis l'onglet Terminal des Préférences dans la v2), après quoi c'est juste mate -w.
#SublimeText : il faut avoir un appel en ligne de commande, là aussi. Sur OSX avec ST2, j'ai un lien symbolique /usr/local/bin/subl vers /Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl, qui est fourni pour ça. Après quoi subl -w.
#GEdit : gedit -w -s
#GVim : gvim --nofork
#Coda : Il vous faut installer coda-cli (généralement via Homebrew, toujours aussi utile…) après quoi coda -w.
#Chocolat : Installez l'appel en ligne de commande (Chocolat > Install Command Line Tool…) après quoi choc -w
#Notepad++ : vous aurez peut-être besoin d'adapter le chemin en fonction de là où vous avez installé Notepad++, mais voici l'idée : 'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin.
#Ultra-Edit : uedit32 /fni
# on macOS , depending on applications, you may have to go inside the application package

==== setting diff and merge tool ===)

setting meld

setting sublime diff

setting p4v from perforce

# based on http://blogs.pdmlab.com/alexander.zeitler/articles/installing-and-configuring-p4merge-for-git-on-ubuntu/
cd ~/Downloads
wget https://cdist2.perforce.com/perforce/r18.2/bin.linux26x86_64/p4v.tgz
tar zxvf p4v.tgz
sudo mkdir /opt/p4v
cd p4v-2020.1.1966006  # you have to get the last version of p4merge on perforce web site , it is free
sudo mv * /opt/p4v
sudo ln -s /opt/p4v/bin/p4merge /usr/local/bin/p4merge
~/.gitconfig
[color]
   ui = true
   diff = true
   branch = auto
   status = auto
[alias]
 new = checkout -b
 co = checkout
 ci = commit
 cm = commit -m
 cam = commit -am
 ca = commit --amend # careful
 st = status
 br = branch
 lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen--> %cr%Creset by %Cblue%cN <%cE>%Creset' --abbre v-commit --date=relative
 hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
 type = cat-file -t
 dump = cat-file -p
 s = status --short
 a = !git add . && git status
 au = !git add -u . && git statustus
 aa = !git add . && git add -u . && git status
 ac = !git add . && git commit
 acm = !git add . && git commit -m
 put = push origin HEAD
 get = pull origin HEAD
[merge]
   keepBackup = false;
   tool = p4merge
[mergetool]
   prompt = false
[mergetool "p4merge"]
   cmd = p4merge "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
   keepTemporaries = false
   trustExitCode = false
   keepBackup = false
[diff]
   tool = p4merge
[difftool]
   prompt = false
[difftool "p4merge"]
   cmd = p4merge "$LOCAL" "$REMOTE"
   keepTemporaries = false
   trustExitCode = false
   keepBackup = false
setting diff tool
git config --global core.editor emacs
# P4Merge
# Meld
# kdiff3
# winMerge
# TortoiseMerge

= setting merge tool

git config --global core.editor emacs
# P4Merge
# Meld
# kdiff3
# winMerge
# TortoiseMerge
mergetool.keepBackup false
mergetool.keepTemporaries false
mergetool.prompt false

git-log

git log
git log -graph
git log -graph --oneline
git log --oneline
git log -- <filePath>
git log --oneline <filePath>

git-branch

git branch
git branch -a 
git branch -r
git branch -D <branchname>
git branch -m newNameOfLocalBranch
git branch -m branchToRename newNameOfBranchToRename
git branch --set-upstream-to=origin/nomBranchRemote nomBranchLocale


git-tag

git tag

git-status

git status

git-stash

git stash
git stash pop

git-fetch

git fetch

git-pull

git pull
git pull --rebase

git-checkout

git checkout
git checkout -b <branchname>


git-merge

git merge


resolving conflict with binary files

If you want to take your changes over the ones you’re merging in, simply run:

 git checkout --ours -- path/to/file.binary

Inversely, if you want to take the merging changes over your own you can run

 git checkout --theirs -- path/to/file.binary

This works on non-binary files, too, but keep in mind it’s all-or-nothing. Either use all your changes to a file, or all theirs.

git-rebase

get rebase
git rebase -i
git rebase --interractive --onto 


git-cherry-pick

git cherry-pick <commit sha1>
git cherry-pick --abort

git-rerere

git rerere can be activated and set to be used automatically by git rebase

git-reflog

git reflog

git-diff

git diff
git diff <filePath>

git-difftool

git difftool
git difftool <filePath>

git-mergetool

git mergetool

git-reset

git reset

git-add

git add
git add -a
git add -p

git-rm

git rm

git-mv

git mv

git-grep

git grep

git-commit

git commit
git commit -m "commit message text"
git commit -p
git commit --amend

git-push

git push
git push origin nomBranche

git-stash

git stash
git stash pop
git stash clear
git stash applymvnc

git-reset

git reset --hard origin/<myRemoteBranch>


git-alias

alias:
git config --global alias.newCommand 'Commande en entier sans le "git"'
   Exemple : git config --global alias.unstage 'reset HEAD --'
   Usefull ones :
   git config --global alias.st 'status'
   git config --global alias.co 'checkout'
   git config --global alias.cp 'cherry-pick'

git-bisect

git bisect

git-blame

git blame  <filepath>, list all the changes on a file for each lines and tell which commiter did them (the name have to be set for each commiter)

How-To

  • how to get a file history
 git log -- <filePath>
 git log <filepath>
  • using reflog and git reset to cancel actions
  • resetting
  • cancelling the last pushed commit
 git revert
  • cancelling the last commit (not yet pushed)
 git reset HEAD~
  • resetting a local branch after the remote branch on the server
 git reset --hard origin/<myRemoteBranch>
  • This removes everything from the index, then just run:
 git rm -r --cached .
  • Applying a .gitignore file added well after having committed file
 git rm -r --cached .
 git add .
 git commit -m ".gitignore is now working"


  • patches
    • create a patch
 git diff >> patch file
 git format-patch patch-file
** accept a patch
 git apply patch_file


  • subtrees