first example is for git (command-line), second is for magit
- git
- DVCS (Distributed Version Control System)
advantages of a VCS:
- collaboration
- storing/restoring versions
- understanding changes
- backup
- create
.git/
- create HEAD file referencing master (no commit)
git init [<dir>]
magit-init
displays paths that:
- untracked
- not in index file (not ignored by .gitignore)
- unstaged
- working tree state different from index virtual working tree state
- staged
- index virtual working tree state different from HEAD referenced branch snapshot
git status
C-x g
update index to set paths to staged
git add <path>..
s: single S: all
update index to set paths to untracked/unstaged
git reset HEAD <path>..
u: single U: all
snapshot of the index changes and HEAD branch update
git commit git commit --amend
c c: commit c a: amend
- the amend option only update last commit
manage branches
git branch <branch> git branch -d <branch>: if merged git branch -D <branch>: if not merged
b c: create and checkout b k: delete branch
updates files in the working tree to match the version in the snapshot
git checkout <branch>
b b:
merge the current branch with another
git merge <branch>
m m:
- fast forward
- update current branch to the newest, no commit
- 3-way merge
- resolve two branch last commits in a new commit in which conflicts are solved row by row
manage remote urls
git remote add <name> <url> git remote rm <url> git remote rename <old> <new>
magit-remote-...
git clone <url>
magit-clone
git push [<remote> <branch>]
P p:
to prevent you from overwriting commits, git won’t let you push when it results in a non fast-forward merge in the destination repository.
--force-with-lease
force push ensuring none of your teammates have committed
if the remote history has diverged from your history, you need to fetch the remote branch and merge it into your local one, then try pushing again.
git fetch [<remote> <branch>]
f p:
- pull
- fetch + merge
git stash: only tracked git stash -u: also untracked git stash -a: also untracked and ignored git stash pop git stash apply
z z: save z p: pop z a: apply
apply commits of current branch to the head of another
git rebase <branch> git rebase -i <branch>
r e: r i:
interactively permit to manage history of commit: squashing, fixuping, deleting, ordering..
--autostash
in order: stash, rebase and stash pop uncommitted changes
naming convention v0.0.1
git tag <tag> git push origin --tags git tag -d <tag> git push origin :<tag>
t t: P t: t k: t p:
apply reverse changes
git revert <commit>.. git revert -n <commit>: no commit (change only working directory and index)
V V: v:
reset the history
git reset ..
X ..
- soft
- HEAD
- mixed
- HEAD, index (default)
- hard
- HEAD, index, working tree
navigation:
HEAD^n
specify which parent followHEAD~n
specify for how many
(characters can be combined: HEAD^x~y
)
log the working file magit-log-buffer-file
git reflog
l H:
- checkout
HEAD@{n}
to recall a state
chunks can be managed from magit-status
s: stage u: unstage k: discard v: revert