monkindey / KihoSaid

always wip, take everything I thought and saw down
1 stars 0 forks source link

Git 命令 #6

Open monkindey opened 8 years ago

monkindey commented 8 years ago

Table Of Content (TOC)

Reference

monkindey commented 8 years ago

git checkout -

jump back to your last branch

跳到你最后使用的分支上

monkindey commented 8 years ago

git shortlog -sn

Quickly get a list of contributors and see how many commits each person has

快速预览贡献者列表还有他们的提交数

git shortlog

monkindey commented 8 years ago

git log

让Git的输出更友好: 多种颜色和自定义log格式

monkindey commented 8 years ago

git commit --amend

Great for squashing staged files into your last commit.

修改你最后一次提交

改写提交

monkindey commented 8 years ago

git rm --cached

当你想要把之前追踪文件的变成不追踪了

http://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore

monkindey commented 8 years ago

git branch --all | grep ${query}

How do you search for a branch in SourceTree

monkindey commented 8 years ago

git config

overview the git config

  • git config --local -l
  • git config --global -l
  • git config --system -l

add the config item

git config add user.name "monkindey"

https://github.com/monkindey/note/issues/6#issuecomment-297894252

monkindey commented 7 years ago

git 同步 github fork 出来的分支

  1. git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY
  2. git fetch upstream
  3. git checkout master
  4. git merge upstream/master
monkindey commented 7 years ago

Move existing, uncommited work to a new branch in Git

http://stackoverflow.com/questions/1394797/move-existing-uncommited-work-to-a-new-branch-in-git

monkindey commented 7 years ago

Oh, Shit, Git

monkindey commented 7 years ago

Git list untracked files

背景是这样子, 我有新增一个目录bench, 里面下载了node_modules, 但是我在根目录设置了.gitignore是有node_modules, 但是我不太确定bench里面的node_modules会不会被忽略

git ls-files --others --exclude-standard

http://stackoverflow.com/questions/3801321/git-list-only-untracked-files-also-custom-commands

monkindey commented 7 years ago

git ignore tracked file

背景是这样子的, 如果对一些文件给commit了, 突然想不跟踪它了, 怎么办呢? 在.gitignore里面再设置是没用的, 只有先去掉它的追踪然后再加上才有效果.

这个重复了

monkindey commented 7 years ago

git create a remote branch

git push <remote-name> <branch-name>

remote-name is typically origin

http://stackoverflow.com/questions/1519006/how-do-you-create-a-remote-git-branch

monkindey commented 7 years ago

Warning: push.default is unset

monkindey commented 7 years ago

How to handle big repositories with Git

The React project Size is huge.

monkindey commented 7 years ago

How can I check out a GitHub pull request?

git fetch origin pull/ID/head:BRANCHNAME
git checkout BRANCHNAME
monkindey commented 7 years ago

Count number of branches in a repo

git branch | wc -l
monkindey commented 7 years ago

Git checkout remote branch

git fetch

git checkout <branch>
monkindey commented 7 years ago

What's the simplest way to get a list of conflicted files?

不过这个也不一定准哈, 只是列出没有被合并的文件名而已

git diff --name-only --diff-filter=U
monkindey commented 7 years ago

How to list all the files in a commit?

git show --pretty="" --name-only <commit>
monkindey commented 7 years ago

Find out which remote branch a local branch is tracking

git branch -vv
monkindey commented 7 years ago

How do I configure Git to automatically pull from current branch when using “git pull”?

背景

git pull 的时候出现pull太多分支了, 所以打算默认git pull当前分支的

命令

git branch -u origin/<branch_name>
monkindey commented 7 years ago

Better Git configuration

monkindey commented 7 years ago

Git - What is the difference between push.default “matching” and “simple”

Push all branches

git config --global push.default matching

Push only the current branch

git config --global push.default simple
monkindey commented 7 years ago

Git config

monkindey commented 7 years ago

A few of my Git tricks, tips and workflows

monkindey commented 7 years ago

Undo working copy modifications of one file in Git?

git checkout -- file

重置你本地修改文件

monkindey commented 7 years ago

Undo the Git last commit

git reset --hard HEAD~

取消你最近的一次提交, 本地也不会保留

git reset HEAD~

取消你最近的一次提交, 本地会保留

monkindey commented 7 years ago

How to see the changes in a commit?

git show <commit>

monkindey commented 7 years ago

How to get ONLY filename with path using Git log

通过 git log | grep | sort | uniq等等命令组合, 让我们认识到命令行的强大和灵活

monkindey commented 7 years ago

How to switch git user at terminal?

Mac党要去keyChains那里删除之前保留的密码

monkindey commented 7 years ago

How to get the current branch name in Git?

monkindey commented 7 years ago

git 撤退所有修改的文件

一种场景是如果你重新编译了webpack, 会导致build目录下地文件很多都需要提交的感觉, 但 其实并没有修改过, 这个时候用下面的目录给祛除掉。

git checkout -- `git diff --name-only | tr '\n' ' '`
monkindey commented 7 years ago

Show git diff on file in staging area

git diff --staged
monkindey commented 7 years ago

Rollback to an old Git commit in a public repo

一种场景就是我要看某个commit的文件长什么样子的. 可以这样子弄

git checkout <commit-id>

它有点像是新创建一个中间branch一样,你可以通过

git checkout <branch>

切回来

monkindey commented 7 years ago

How to merge my local uncommitted changes into another Git branch?

一种场景就是我开发了, 但是我提交错分支了

git stash
git checkout branch2
git stash pop
monkindey commented 7 years ago

Delete Remote Branch

git push -d origin <branch_name>

monkindey commented 7 years ago

找到某个commit某个文件的diff

g diff <commit>^..<commit> -- <filepath>
monkindey commented 7 years ago

List all commits for a specific file

git log --follow filename
monkindey commented 7 years ago

gitignore

场景

.gitignore在git库里面, 我想修改, 但是不想我一些本地文件让git识别到。

可以通过git update-index --assume-unchanged .gitignore让git不要track gitignore文件, 然后你就可以愉快得添加.gitignore了

monkindey commented 7 years ago

How to Contribute to an Open Source Project on GitHub

跟着Kent C. Dodds学习如何参与开源项目开发

monkindey commented 7 years ago

Commit history on remote repository

git log remotename/branchname
monkindey commented 7 years ago

Updates were rejected because the tip of your current branch is behind

有一种情况就是你提交了PR, 然后还没被合并, 官方又有新的东西加入, 你又rebase了, 导致你git push之后每次都叫你来git pull一次但是其实是没有什么改动的。所以导致又出现一个merge commit历史

可以用上这个方法

git push -f origin <branch>
monkindey commented 6 years ago

Git in depth

深入了解Git,而且还是视频的,学习起来更加好玩。还有就是我还没看呢。

monkindey commented 6 years ago

Git - push current branch shortcut

git config --global push.default current
monkindey commented 6 years ago

Git Legit

简化你的Git工作流

monkindey commented 6 years ago

Git rebase

有时候你要rebase你的分支,但是出现冲突怎么办呢?

monkindey commented 6 years ago

How do I rename a local Git branch?

# 1
git branch -m <oldname> <newname>
# 2
git branch -m <newname>
monkindey commented 6 years ago

Why You Should Care About Squash and Merge in Git

Squash and Merge in Git

monkindey commented 6 years ago

git 设置代理

设置代理

git config --global http.https://github.com.proxy socks5://127.0.0.1:1080

取消代理

git config --global --unset http.https://github.com.proxy