// Checking the Status of Your Files $ git status // Tracking New Files // 每次修改都重新add添加更改 $ git add README // Ignoring Files $ cat .gitignore // Viewing Your Staged and Unstaged Changes $ git diff $ git diff --staged $ git diff --cached // Committing Your Changes $ git commit $ git commit -m "Story 182: Fix benchmarks for speed" // Skipping the Staging Area $ git commit -a -m 'added new benchmarks' // Removing Files $ rm PROJECTS.md $ git rm PROJECTS.md $ git rm --cached README // Moving Files $ git mv file_from file_to
Viewing the Commit History
1 2
// 很多操作,这里先写一个 $ git log
Undoing Things
1 2 3 4 5 6 7 8 9 10 11
$ git commit --amend // Unstaging a Staged File $ git reset HEAD CONTRIBUTING.md // Unmodifying a Modified File $ git checkout -- CONTRIBUTING.md // Revert merged $ git merge --abort // Revert any operation $ git reflog // 3 is HEAD number $ git reset --hard HEAD~3
Working with Remotes
1 2 3 4 5 6 7 8 9 10 11
// Showing Your Remotes $ git remote -v // Fetching and Pulling from Your Remotes $ git fetch [remote-name] // Pushing to Your Remotes $ git push origin master // Inspecting a Remote $ git remote show origin // Removing and Renaming Remotes $ git remote rm paul $ git remote rename pb paul
// Basic Merging // 合并两个没有前后关系的分支(上图master和iss53都是在一个点继续提交的) $ git checkout master // Switched to branch 'master' $ git merge iss53 // Merge made by the 'recursive' strategy. // 这种情况会产生一个新的提交(master会指向这个提交,提交由前面C3,4,5合并生产)
// Basic Merge Conflicts // 上面情况可能会产生冲突,下面介绍解决冲突 // 解决冲突前,git没法产生新的提交点 $ git mergetool // 这里不继续介绍了,建议用图形工具 // use "git commit" to conclude merge
Branch Management
1 2 3 4
$ git branch // 查看当前所有分支(主要自己本地(remote)建的) $ git branch -v // -v带最后一次提交信息 // To see which branches are already merged into the branch you’re on $ git branch --merged //(--no-merged)