Helpful git commands | Drupal 8

Helpful git commands

Submitted by editor on Mon, 11/16/2015 - 16:30

#Download / Get git repository
git clone http://url-of-your-git/project.git

#Show remore url
git remote -v

 

#Quickly Resolve conflict
grep -lr '<<<<<<<' .
git checkout --ours PATH/FILE
git checkout --theirs PATH/FILE

 

grep -lr '<<<<<<<' . | xargs git checkout --ours
grep -lr '<<<<<<<' . | xargs git checkout --theirs

#Remove all local changes
git reset --hard
git pull

#Switch / Change / Move HEAD branch
git remote set-head origin new_head_branch

Saving / Caching  Git password
git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=28800' #28800=8 hours

 

#Confugure Name/ EMail
git config --global user.name "Your Name"
git config --global user.email you@email.com

#Delete a branch /!\ CAUTION
#Local
git branch -d the_local_branch
#Remote
git push origin :the_remote_branch

 

Show Different:
View finally comited files and the commit ID
git log --name-status HEAD^..HEAD
View A commit's Files
git diff-tree --no-commit-id --name-only -r THE_COIMMIT_ID
View the different
git diff THE_COIMMIT_ID^!

Update local repository info
git fetch

Update Child branch from Original (Mail) branch

git pull origin MMAIN_BRANCH
git fetch origin MMAIN_BRANCH # (pull)

git checkout feature/CHILD_BRANCH
git merge FETCH_HEAD

git add .
git commit -m 'Resolve confilcts'
git push origin HEAD

Show difference between two commits.

1. get the commit id's (git log). you have something like:

commit e0c614809a2ab57ce7e34638306fe3d8e660d0ca
Author: You <you@example.com>
Date:   Sun Dec 3 10:13:15 2017 +0100
    The comment N°1
commit c070cf2b08b6701a61ac23d6ab1849ddd5cc61bc
Author: You <you@example.com>
Date:   Fri Dec 1 15:12:46 2017 +0100
    The comment N°2
commit 684cfed344f663945036db1fc52b6e45bba6a2c3
Author: You <you@example.com>
Date:   Fri Dec 1 11:19:50 2017 +0100
    The comment N°3
commit 4b5daeb08e3ac1a3b8e1830d8ca820622a9539ef
...

2. Show difference using : git diff COMMIT_FROM..COMMIT_TO
Ex :
git diff 684cfed344f663945036db1fc52b6e45bba6a2c3..c070cf2b08b6701a61ac23d6ab1849ddd5cc61bc

 

 

Tags

Add new comment