2022年8月6日 星期六

Introduction to git and GitHub 2022

 Week 1


Reference

https://git-scm.com/docs/gittutorial

commit
mkdir project
git init
git add .
git commit
touch file1 file2 file3
git add file1 file2 file3
git diff --cached
git status
git commit
git commit -a
git log
git log -p
git log --stat --summary

branch
git branch experimental
git branch
git switch experimental
echo first >> file1
git commit -a
git switch master
echo second >> file1
git commit -a
git merge experimental
git diff
git commit -a
git branch -d experimental
git branch -D crazy-idea
TBC

Collaboration

git clone /home/alice/project myrepo\
cd myrepo
echo bob >> file.txt
git commit -a
alice$ cd /home/alice/project
alice$ git pull /home/bob/myrepo master // pull = fetch + merge to current branch
alice$ git fetch /home/bob/myrepo master
alice$ git log -p HEAD..FETCH_HEAD // range notation
alice$ gitk HEAD..FETCH_HEAD
alice$ git remote add bob /home/bob/myrepo
alice$ git fetch bob
alice$ git log -p master..bob/master  // better range notation
alice$ git merge bob/master
alice$ git pull . remotes/bob/master // what? pulling from her own remote-tracking branch?
bob$ git pull  // pull = fetch + merge to current branch
bob$ git config --get remote.origin.url
/home/alice/project
bob$ git config -l  // show git clone config
bob$ git branch -r origin/master
bob$ git clone alice.org:/home/alice/project myrepo

History

git log
git show c82a22c39cbc32576f64f5c6b3f24b99ea8149c7
git show c82a22c39c
git show c82a22c39
git show c82a22c3
git show c82a22c
git show c82a22
git show HEAD # tip of current branch
git show experiment # tip of experiment branch
git show HEAD^ # parent of HEAD
git show HEAD^^ # grandparent of HEAD
git show HEAD~4 # great-great grandparent of HEAD
git show HEAD^1 # same as HEAD^
git show HEAD^2 # second parent of HEAD
git tag v2.5 1b2e1d63ff
git diff v2.5 HEAD
git branch stable v2.5  # create a new branch named stable based on v2.5
git reset --hard HEAD^  # reset to state at HEAD^ i.e. parent of HEAD
git grep "hello" v2.5
git log v2.5..v2.6 # commit between v2.5 and v2.6
git log v2.5.. # commit since v2.5
git log --since="2 week ago"  # commit from the last 2 weeks
git log v2.5.. Makefile # commit since v2.5 which modify Makefile
gitk --since="2 weeks ago" drivers/ # commits that modify directory
 

Diff

diff apple banana

diff -u apple banana

diff -u apple banana > diff.diff

meld, kdiff3, vimdiff

patch banana < diff.diff




沒有留言:

張貼留言

2023 Promox on Morefine N6000 16GB 512GB

2023 Promox on Morefine N6000 16GB 512GB Software Etcher 100MB (not but can be rufus-4.3.exe 1.4MB) Proxmox VE 7.4 ISO Installer (1st ISO re...