我刚才提交了什么?
(main)$ git show
$ git log -n1 -p
我的提交信息(commit message)写错了
$ git commit --amend --only
$ git commit --amend --only -m 'xxxxxxx'
我提交(commit)里的用户名和邮箱不对
$ git commit --amend --author "New Authorname <authoremail@mydomain.com>"
我想从一个提交(commit)里移除一个文件
$ git checkout HEAD^ myfile
$ git add -A
$ git commit --amend
我想删除我的的最后一次提交(commit)
$ git reset HEAD^ --hard
$ git push -f [remote] [branch]
(my-branch*)$ git reset --soft HEAD@{1}
删除任意提交(commit)
$ git rebase --onto SHA1_OF_BAD_COMMIT^ SHA1_OF_BAD_COMMIT
$ git push -f [remote] [branch]
我尝试推一个修正后的提交(amended commit)到远程,但是报错:
To https://github.com/yourusername/repo.git
! [rejected] mybranch -> mybranch (non-fast-forward)
error: failed to push some refs to 'https://github.com/tanay1337/webmaker.org.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
(my-branch)$ git push origin mybranch -f
我意外的做了一次硬重置(hard reset),我想找回我的内容
(main)$ git reflog
(main)$ git reset --hard SHA1234
暂存(Staging)
我需要把暂存的内容添加到上一次的提交(commit)
(my-branch*)$ git commit --amend
我想要暂存一个新文件的一部分,而不是这个文件的全部
$ git add --patch filename.x
$ git add -N filename.x
我想把在一个文件里的变化(changes)加到两个提交(commit)里
我想把暂存的内容变成未暂存,把未暂存的内容暂存起来
$ git commit -m "WIP"
$ git add .
$ git stash
$ git reset HEAD^
$ git stash pop --index 0
未暂存(Unstaged)的内容
我想把未暂存的内容移动到一个新分支
$ git checkout -b my-branch
我想把未暂存的内容移动到另一个已存在的分支
$ git stash
$ git checkout my-branch
$ git stash pop
我想丢弃本地未提交的变化(uncommitted changes)
# one commit
(my-branch)$ git reset --hard HEAD^
# two commits
(my-branch)$ git reset --hard HEAD^^
# four commits
(my-branch)$ git reset --hard HEAD~4
# or
(main)$ git checkout -f
$ git reset filename
我想丢弃某些未暂存的内容
$ git checkout -p
# Answer y to all of the snippets you want to drop
$ git stash -p
# Select all of the snippets you want to save
$ git reset --hard
$ git stash pop
$ git stash -p
# Select all of the snippets you don't want to save
$ git stash drop
分支(Branches)
我从错误的分支拉取了内容,或把内容拉取到了错误的分支
(main)$ git reflog
ab7555f HEAD@{0}: pull origin wrong-branch: Fast-forward
c5bc55a HEAD@{1}: checkout: checkout message goes here
$ git reset --hard c5bc55a
我想扔掉本地的提交(commit),以便我的分支与远程的保持一致
(my-branch)$ git status
# On branch my-branch
# Your branch is ahead of 'origin/my-branch' by 2 commits.
# (use "git push" to publish your local commits)
#
(main)$ git reset --hard origin/my-branch
我需要提交到一个新分支,但错误的提交到了main
(main)$ git branch my-branch
(main)$ git reset --hard HEAD^
(main)$ git reset --hard a13b85e
HEAD is now at a13b85e
(main)$ git checkout my-branch
我想保留来自另外一个ref-ish的整个文件
(solution)$ git add -A && git commit -m "Adding all changes from this spike into one big commit."
-
分支 solution, 拥有原型方案, 领先 develop 分支。 -
分支 develop, 在这里你应用原型方案的一些内容。
(develop)$ git checkout solution -- file1.txt
# On branch develop
# Your branch is up-to-date with 'origin/develop'.
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: file1.txt
我把几个提交(commit)提交到了同一个分支,而这些提交应该分布在不同的分支里
(main)$ git log
commit e3851e817c451cc36f2e6f3049db528415e3c114
Author: Alex Lee <alexlee@example.com>
Date: Tue Jul 22 15:39:27 2014 -0400
Bug #21 - Added CSRF protection
commit 5ea51731d150f7ddc4a365437931cd8be3bf3131
Author: Alex Lee <alexlee@example.com>
Date: Tue Jul 22 15:39:12 2014 -0400
Bug #14 - Fixed spacing on title
commit a13b85e984171c6e2a1729bb061994525f626d14
Author: Aki Rose <akirose@example.com>
Date: Tue Jul 21 01:12:48 2014 -0400
First commit
(main)$ git reset --hard a13b85e
HEAD is now at a13b85e
(main)$ git checkout -b 21
(21)$
(21)$ git cherry-pick e3851e8
(21)$ git checkout main
(main)$ git checkout -b 14
(14)$
(14)$ git cherry-pick 5ea5173
我想删除上游(upstream)分支被删除了的本地分支
$ git fetch -p
我不小心删除了我的分支
(main)$ git checkout -b my-branch
(my-branch)$ git branch
(my-branch)$ touch foo.txt
(my-branch)$ ls
README.md foo.txt
(my-branch)$ git add .
(my-branch)$ git commit -m 'foo.txt added'
(my-branch)$ foo.txt added
1 files changed, 1 insertions(+)
create mode 100644 foo.txt
(my-branch)$ git log
commit 4e3cd85a670ced7cc17a2b5d8d3d809ac88d5012
Author: siemiatj <siemiatj@example.com>
Date: Wed Jul 30 00:34:10 2014 +0200
foo.txt added
commit 69204cdf0acbab201619d95ad8295928e7f411d5
Author: Kate Hudson <katehudson@example.com>
Date: Tue Jul 29 13:14:46 2014 -0400
Fixes #6: Force pushing after amending commits
(my-branch)$ git checkout main
Switched to branch 'main'
Your branch is up-to-date with 'origin/main'.
(main)$ git branch -D my-branch
Deleted branch my-branch (was 4e3cd85).
(main)$ echo oh noes, deleted my branch!
oh noes, deleted my branch!
(main)$ git reflog
69204cd HEAD@{0}: checkout: moving from my-branch to main
4e3cd85 HEAD@{1}: commit: foo.txt added
69204cd HEAD@{2}: checkout: moving from main to my-branch
(main)$ git checkout -b my-branch-help
Switched to a new branch 'my-branch-help'
(my-branch-help)$ git reset --hard 4e3cd85
HEAD is now at 4e3cd85 foo.txt added
(my-branch-help)$ ls
README.md foo.txt
我想删除一个分支
(main)$ git push origin --delete my-branch
(main)$ git push origin :my-branch
(main)$ git branch -D my-branch
我想从别人正在工作的远程分支签出(checkout)一个分支
(main)$ git fetch --all
(main)$ git checkout --track origin/daves
Branch daves set up to track remote branch daves from origin.
Switched to a new branch 'daves'
Rebasing 和合并(Merging)
我想撤销rebase/merge
(my-branch)$ git reset --hard ORIG_HEAD
我已经rebase过, 但是我不想强推(force push)
(main)$ git checkout my-branch
(my-branch)$ git rebase -i main
(my-branch)$ git checkout main
(main)$ git merge --ff-only my-branch
我需要组合(combine)几个提交(commit)
(my-branch)$ git reset --soft main
(my-branch)$ git commit -am "New awesome feature"
(my-branch)$ git rebase -i main
(main)$ git rebase -i HEAD~2
pick a9c8a1d Some refactoring
pick 01b2fd8 New awesome feature
pick b729ad5 fixup
pick e3851e8 another fix
# Rebase 8074d12..b729ad5 onto 8074d12
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
pick a9c8a1d Some refactoring
pick 01b2fd8 New awesome feature
f b729ad5 fixup
f e3851e8 another fix
pick a9c8a1d Some refactoring
pick 01b2fd8 New awesome feature
s b729ad5 fixup
s e3851e8 another fix
Newer, awesomer features
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# rebase in progress; onto 8074d12
# You are currently editing a commit while rebasing branch 'main' on '8074d12'.
#
# Changes to be committed:
# modified: README.md
#
(main)$ Successfully rebased and updated refs/heads/main.
安全合并(merging)策略
(main)$ git merge --no-ff --no-commit my-branch
我需要将一个分支合并成一个提交(commit)
(main)$ git merge --squash my-branch
我只想组合(combine)未推的提交(unpushed commit)
(main)$ git rebase -i @{u}
检查是否分支上的所有提交(commit)都合并(merge)过了
(main)$ git log --graph --left-right --cherry-pick --oneline HEAD...feature/120-on-scroll
(main)$ git log main ^feature/120-on-scroll --no-merges
交互式rebase(interactive rebase)可能出现的问题
这个rebase 编辑屏幕出现'noop'
noop
-
检查确保主(main)分支没有问题 -
rebase HEAD~2 或者更早
有冲突的情况
(my-branch)$ git status
On branch my-branch
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: README.md
<<<<<<< HEAD
some code
=========
some code
>>>>>>> new-commit
(main*)$ git mergetool -t opendiff
(my-branch)$ git add README.md
(my-branch)$ git rebase --continue
(my-branch)$ git rebase --abort
Stash
暂存所有改动
$ git stash
$ git stash -u
暂存指定文件
$ git stash push working-directory-path/filename.ext
$ git stash push working-directory-path/filename1.ext working-directory-path/filename2.ext
暂存时记录消息
$ git stash save <message>
$ git stash push -m <message>
使用某个指定暂存
$ git stash list
$ git stash apply "stash@{n}"
$ git stash apply "stash@{2.hours.ago}"
暂存时保留未暂存的内容
$ git stash create
$ git stash store -m
文章来源于:单片机与嵌入式 原文链接本站所有转载文章系出于传递更多信息之目的,且明确注明来源,不希望被转载的媒体或个人可与我们联系,我们将立即进行删除处理。相关文章
因外部环境发生变化,大量企业面试第一轮启用AI招聘?(2022-12-23)享一个你处理过最复杂的突发事件”“请分享一段曾经做过的市场分析”……这是应届金融专业本科毕业生秋秋,在9月参加的一次秋招面试时的经历。 面对僵化的声音、模板化的问题,没有眼神交互,却有答题时限的AI面试系统,从未......关于单片机学习和就业那些道与术(2022-12-15)大家要注意代码是靠调出来的,不是凭空想出来的。 最后大家一定要多和同部门同事搞好关系,多请吃饭喝奶茶,为后面问问题做铺垫,大方,不白嫖的性格到哪里都受欢迎,至少不会被排斥。 三、面试找工作的学习重点 脱离需求,你的......两道面试题所引发的C指针的思考(2023-08-01)两道面试题所引发的C指针的思考;C语言是一门使用比较广泛的高级编程语言,而指针则是C语言的精髓所在,可以说学习C语言不会灵活使用指针就谈不上精通C语言。但是由于C语言......9404-05采样扩展实时示波器的功能特点及应用(2023-04-07)可以使用四个独立的缩放跟踪视图来检查波形细节。 各种自动和用户可配置的信号完整性测量、数学、统计视图和极限测试模板,用于对脉冲和定时性能、抖动、RZ和NRZ眼图的验证和分析。工业标准通信模板测试多,如PCIe......RTC1000示波器的特点优势及应用性能分析(2023-04-07)分析信号频谱 多合一示波器 ◇ 示波器 ◇ 逻辑分析仪 ◇ 协议分析仪 ◇ 波形和码型发生器 ◇ 数字电压表 ◇ 部件测试仪 ◇ 频谱分析仪 ◇ 模板测试模式 具有可扩展性,是一......TDS3000C数字荧光示波器的特点优势及应用分析(2023-04-03)测试和视频调试。 TDS3AAM高级分析模块 TDS3LIM极限测试模块 TDS3TMT通信模板测试模块 TDS3VID扩展视频分析模块 TDS3SDI 601串行/数字视频模块 4、设置/操作简单-自动......调查表明:45%求职者使用AI生成和改进简历(2024-01-29)可以判断求职者是否一直或大部分时间都在使用生成式AI。Schultz指出,求职者应该采取措施验证AI工具的输出,以确保在面试时不会出现任何意外。 她说:“我认为,无论求职者使用什么生成式AI工具......采用LabVIEW的图形化程序语言实现数字仪表测试系统的设计(2023-05-25)种很直观的方法建立前面板人机界面和程序框图。前面板是用户可见的,类似传统仪器的操作面板,利用工具模板从控制模板中添加输入控制器和输出指示器,控制器和指示器种类可选择。程序......Fluke 729自动压力校验仪的主要特性及功能特点分析(2023-05-10)生成和调节高达 300 psi 的压力 使用机载测试模板轻松记录校准过程 内部自动微调压力 可测量、输出和模拟 4 ~ 20 mA 信号 24V 回路电源,为受测变送器供电 明亮的双信道/三信......千兆以太网一致性分析测试的操作方式与测试方案(2024-04-16)802.3 标准对 1000BASE-T 物理层一致性测试的规定,被测设备应要在标准规定的四种测试模式下完成一系列一致性测试,模式可分为以下四种: ●模式1:模板测试、峰值电压测试、衰落测试 ●模式2......