赞
踩
- 查看所有分支
- git branch -a
-
- 拿特定branch的代码
- git checkout origin/daily/1.4.1
-
- 切换branch
- git checkout #branch name#
- (如果是线上已有的 branch,一定不要加 -b,加 -b 就是从当前 branch 新建的)
-
- 创建branch
- git checkout –b #branch name#
-
- 删除branch
- git branch –d #branch name#
-
- 丢弃最新的commit
- git reset --hard HEAD~1
-
- Revert 最新的commit,去除commit,但是不丢弃改动本身
- git reset --soft HEAD~1
-
- 查看单个文件 history
- gitk [filename]
- or to follow filename past renames
- gitk --follow [filename]
-
- git uncommit 自己最近的 commit
- 如果自己最近 commit 了多个,就执行如下,其中 asdf 是自己最近第一条 commit 的前一条 commit
- git reset --soft "asdf"
-
- 把新添加的文件也stash
- git stash -u
-
- 查看某branch自己的提交历史
- git log develop --author=your.name --oneline -10
-
- git revert 已经 push 的 commit
- git revert <commit_hash>
- git revert <oldest_commit_hash>..<latest_commit_hash>
- https://stackoverflow.com/questions/22682870/git-undo-pushed-commits
-
- Git cherry-pick 多个 commit
- git cherry-pick -n 90f121ae7 4a42a1d33 e257dcda6 6760de43d 0784f0cde 80a4c3bf6 321482012
- 加 -n 是为了 cherry-pick 过来后不自动 commit
- cherry-pick 建议流程
- 1. 多个 commit 同时 cherry-pick
- 2. 如果中间提示有冲突,则 处理冲突,然后 git cherry-pick --continue
- 3. 如果git cherry-pick --continue 提示本地 需要 stash/commit,则先 stash,在 continue (不过用 commit 可能更好?因为会保留 commit 号码?)
- cherry-pick 全部完成后,按照 stash 顺序重新应用到 本地 (如果前面不用 stash 而用 commit 就不需此)
-
- 查看 branch 的地址
- git remote -v
- origin http://gitlab.alibaba-inc.com/DRDS/manager.git (fetch)
- origin http://gitlab.alibaba-inc.com/DRDS/manager.git (push)
-
- 查看一个 branch 内两个日期之间的 不同文件
- https://stackoverflow.com/questions/1161609/how-can-i-get-the-diff-between-all-the-commits-that-occurred-between-two-dates-w
- git diff --stat @{2018-10-24}..@{2018-8-1}
- or
- git diff --stat @{2.weeks.ago}..@{last.week}
-
- git clone 指定 branch
- git clone --single-branch -b branch host:/dir.git
- 如 git clone -b feature/support_cross_schema_query http://gitlab.my-inc.com/middleware/my_proj.git
-
- 取消 merge
- git reset --merge
-
- checkout 某一个 commit 快照
- git reset --hard commit_sha
在本 repo 上 commit,但不 push
通过 source tree push 时,手动选择相应 branch。
http://xigua366.iteye.com/blog/2400153
https://stackoverflow.com/questions/4845505/gitx-how-do-i-get-my-detached-head-commits-back-into-master/4845543
1. git reflog and git reflog --all will give you the commit hashes 找到你提交的 commit
git merge HEAD@{1} (后面数字从 git reflog 结果查看)将改动 merge 到当前 branch
https://stackoverflow.com/questions/8197089/fatal-error-when-updating-submodule-using-git
修改 /Users/your.name/Documents/Work/my_proj/.git/config 和
/Users/your.name/Documents/Work/my_proj/.gitmodules 里内容:
[submodule "my-calcite"]
path = my-calcite
url = http://gitlab.my-inc.com/my_proj/my-calcite.git
branch = master
改完之后,一定要执行 git submodule sync
在 history 页面只显示当前 branch 的,然后按 ⌘ (OSX) 选中任意两个 commit,就可以查看二者之间的不同了。
这是需要通过命令行拉一次,就可以了。
则直接采用 force
git checkout -f another-branch
error: The following untracked working tree files would be overwritten by merge:
my-calcite/src/main/java/org/apache/calcite/rel/core/SemiJoin.java
my-calcite/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java
把本地相应文件删除再 pull
或者:
The only commands that worked for me were:
git fetch --all
git reset --hard origin/{{your branch name}}
如:git reset --hard origin/my_dev_mpp_stable_partialy_merged
git status --ignored
1. 工程 git 库根目录
work/project_A/ .gitignore
2. 总目录
/Users/your_name/.gitignore_global
3. exculde 文件
work/manager2/manager/.git/info/exclude
ignore 只会ignore 未 add 的文件,已经add 的文件修改的话不会被 ignore。
例:想把 idea 产生的文件都 ignore 掉,则修改 project_A/.git/info/exclude 文件为:
- # git ls-files --others --exclude-from=.git/info/exclude
- # Lines that start with '#' are comments.
- # For a project mostly in C, the following would be a good set of
- # exclude patterns (uncomment them if you want to use them):
- # *.[oa]
- # *~
- .DS_Store
- .idea
- *.iml
- target
- git config user.name
- git config user.email
- git config --global user.name "your name"
- git config --global user.email "your email"
将 /etc/ssh/ssh_config 里面的
ForwardX11 yes 注释掉
git clone -b dev_jk http://10.1.1.11/service/tmall-service.git
git reflog show my_develop
https://www.jianshu.com/p/1031dd2a6c3a
--depth 会带来问题,就是你本地无论如何 git fetch --all,用 git branch -r 都看不到 remote 的所有分支,也无法通过 git checkout 切换分支
git branch -a does not show all remote branches - Stack Overflow --no-single-branch
1.打开git bash。
2.可以查看用户名:git config user.name
3.切换用户:git config --global user.name "xxx"
4.切换邮箱:git config --global user.email "xxx"。
5.切换成功。
$HOME/.gitconfig
或者使用:
git config --global --edit
碰到 Permission denied (publickey):
Error: Permission denied (publickey) - GitHub Docs
error: RPC failed; HTTP 504 curl 22 The requested URL returned error: 504 Gateway Time-out
改用:
git pull web_url branch_name
如:
git pull http://gitlab.xxxxxxxxx-inc.com/middleware/tddl5.git xxxxx_develop
参考此文档生成一个 token:
下面的密码输入生成的 token
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。