Use Git
Apr 19, 2014 · 3 分钟阅读

Getting Help:

$ git help <verb>

Your Configure:

$ git config --list
$ git config --global user.name "[name]"
$ git config --global user.email "[email address]"
$ git config --global user.name "[another name]"

Getting a Git Repository:

$ git init [project-name]
$ git clone [url] [project-name]

Ignoring Files:

# no .a files
*.a
# but do track lib.a, even though you're ignoring .a files above
!lib.a
# only ignore the root TODO file, not subdir/TODO
/TODO
# ignore all files in the build/ directory
build/
# ignore doc/notes.txt, but not doc/server/arch.txt
doc/*.txt
# ignore all .txt files in the doc/ directory
doc/**/*.txt
$ git update-index --assume-unchanged path/to/file

Untrack Files:

$ git rm -r --cached .
$ git add .
$ git commit -m "untrack some files"

Checking the Status of Your Files:

$ git status

Tracking New Files:

$ git add [file]
$ git add .

Viewing Your Staged and Unstaged Changes:

$ git diff
$ git diff --staged

The Git repository browser

$ gitk

Committing Your Changes:

$ git commit -m "[descriptive message]"
$ git commit -a -m "[descriptive message]"

Removing Files:

$ git rm [file]
$ git rm --cached [file]
$ git mv [file-original] [file-renamed]

Viewing the Commit History:

$ git log
 git log --follow [file]
$ git log -p -2
$ git log --pretty=format:"%h - %an, %ar : %s"
$ git log --pretty="%h - %s" --author=gitster --since="2008-10-01" --before="2008-11-01" --no-merges -- directory/
$ git show [commit]
$ git diff [first-branch]...[second-branch]

Undoing Things:

$ git commit --amend
$ git commit --amend -m "<right message>"
git push --force-with-lease <repository> <branch>
$ git reset --soft HEAD^
$ git commit -a -c ORIG_HEAD
$ git unstage <file>
$ git reset --hard HEAD~1
$ git checkout -- <file>

Working with Remotes:

$ git remote -v
$ git remote add [bookmark] [url]
$ git remote update [bookmark]
$ git remote set-url origin [url]
$ git fetch [bookmark]
$ git merge [bookmark]/[branch]
$ git push [alias] [branch]
$ git pull

Basic Branching and Merging:

$ git branch
$ git branch [branch-name]
$ git checkout [branch-name]
$ git checkout -- -[branch-name]
$ git checkout -b [branch-name]
$ git merge [branch-name]
$ git branch --no-merged
$ git branch -d [branch-name]
$ git checkout -b [branch-name] origin/[branch-name]
$ git push origin :[branch-name]

Stashing and Cleaning:

 git stash
$ git stash pop
$ git stash list
$ git stash drop

Tagging:

$ git tag
$ git tag v1.4
$ git show v1.4
$ git push origin v1.4
$ git push origin --tags

Remove file from all previous commits but keep it locally:

$ git rm --cached <file>

see more: Pro Git bookGIT CHEAT SHEET

← Previous Post Next Post →

Ryun的博客
与其感慨路难行,不如马上出发。

atom css design git html javascript jekyll laravel life mac mobile optimization sublime tool vscode vue
mac

About

你好,❤朋友

这里是 Ryun 的博客 📝

📝记录了我学习 🔎的过程

作为一名前端攻城狮 🦁

希望能和大家一起 🔎

共同进步 🏃

🦁的特长:

  • HTML5
  • CSS3
  • JavaScript
  • Vue.js
  • 微信小程序
  • 熟练配合 Node.js、PHP 和 Laravel
  • 熟练使用各种开发和设计工具

🦁喜欢 🆒🆒的东西

对提升效率和美感的事物有兴趣 😋

欢迎 👏交流


see this hugo-theme-dream-ink