- 一般来说,HEAD 指针指向的是当前分支的最新版本。
- create a remote Git branch
1.git checkout -b feature/sh
2.git push origin feature/sh - delete a git branch
git branch -d topic/branch
git branch -D topic/branch
git push origin --delete topic/branch - git change to tag
git fetch --all --tags --prune
git checkout tag_name
- A conflict-marked area begins with
<<<<<<<
and ends with>>>>>>>
. These are also known as the conflict markers. The two conflicting blocks themselves are divided by a=======
-
git checkout -- path/to/file
And that undoes any changes to the file.
An even easier way to undo all unstaged changes on current working directory [1]:
git checkout -- .
[1] - Be warned - you will lose any other unstaged changes you were working on (if any). If you don't know what you are doing, then keep a backup of the files you were working on :)
- merge a git branch into master
git checkout master
git pull origin master
git merger test
git push origin master - how to undo a git commit --amend
git reset --soft @{1} -
git merge origin/fe
- git checkout branch_name //切换到branch_name 的branch
- git checkout -- file.txt 替换掉本地的改动
- git log --pretty=oneline file.name
--oneline
This is a shorthand for "--pretty=oneline --abbrev-commit" used together.
- git show 即可显示具体的某次的改动的修改
- git remote -v 查看远程仓库地址
- git branch 查看当前branch
- git branch -a //查看所有分支
- git reset HEAD a.txt//取消暂存文件
- git reset HEAD CONTRIBUTING.md
- git diff --cached 比较暂存区和版本库中上次提交的差异
- git diff --staged //比较的是工作目录中当前文件和暂存区域快照之间的差异
- git diff --full-index HEAD~ HEAD > /tmp/1.txt //本次commit和上次提交到repo的差异
- git diff --name-only
HEAD~ (which is the very first commit made to the repository), you can use eitherHEAD~~ orHEAD~2 HEAD^
means the first parent of the tip of the current branch.- git rm file1.txt 删除git (本地和远程)数据仓库的文件
- git mv:移动文件
- git commit --amend //修改最后一次提交
- git reset --hard commit_id // 彻底回退到某个版本,本地的源码也会变为上一个版本的内容
- git pull以在你的工作目录中 获取(fetch) 并 合并(merge) 远端的改动。
- git pull origin feature/1 //从分支拉取并合并代码
- git fetch origin feature/1 从分支拉取代码
- git merge origin/feature/
- git push origin master
- git stash 将文件给push到一个临时空间中
- git stash pop //将文件从临时空间pop下来
- git merge master 合并master分支到当前branch
- git status
-
git submodule update --init --recursive$ git archive -o repo.tar --remote=<repo url> <commit id>
- git config commit.template [模板文件名] //这个命令只能设置当前分支的提交模板
git config — —global commit.template [模板文件名] //这个命令能设置全局的提交模板,注意global前面是两杠
error and solve method:
- OSError: Failed to delete remote.origin.url: error: could not lock config file .git/config: Permission denied chmod -R user:group folder
-
Git: “Not currently on any branch.” Is there an easy way to get back on a branch, while keeping the changes?
-
git stash git checkout some-branch git stash pop
-
GIT_DISCOVERY_ACROSS_FILESYSTEM not set
solved: git init
若讀者想確認設定值,可使用 git config --list
命令列出所有Git能找到的設定值:
remove an entry in global configuration with git config?
I'm not sure what you mean by "undo" the change. You can remove the core.excludesfile
setting like this:
git config --global --unset core.excludesfile
And of course you can simply edit the config file:
git config --global --edit
Git Properties
Repository information can be set in a reviewboard.url property on the Git tree. Users may need to do this themselves on their own Git tree, so in some cases, it may be ideal to use dotfiles instead.
To set the property on a Git tree, type:
$ git config reviewboard.url http://reviewboard.example.com
A useful configuration to set is "color.ui". When set to "auto", Git will use text colors to highlight status information, e.g., untracked files will be displayed in red for "git status":
$ git config --global color.ui auto
--global color.ui auto