热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Git-FAQ;UseofGit;GitResetRecover;GitRemoveSomeCommits;GitMultiGithubAccount

GitFAQSomenotesofusingofgitGitGitofficialwebsiteDownloadGitG

Git FAQ

Some notes of using of git

Git

  • Git official website
  • Download Git
  • Git documentation

Tip1 - What if we inadvertently use the Reset command and lose large changes?

Sometimes we do these operations:

git reset --hard HEAD^^^

Sometimes even:

git reset --hard HEAD^^^^^

What if we want to cancel the rollback?

Use

git reflog

Then it shows the reset –hard Logs

389**09 HEAD@{1}: reset: moving to HEAD^^^
d02**f9 HEAD@{2}: reset: moving to HEAD^^
912**c7 HEAD@{3}: reset: moving to HEAD^
e4e**1d (origin/dev) HEAD@{4}: reset: moving to HEAD
e4e**1d (origin/dev) HEAD@{5}: checkout: moving from master to dev
181**f4 (origin/master, master) HEAD@{6}: commit: remove prints
5e9**1d HEAD@{7}: commit (merge): update
634**96 HEAD@{8}: pull origin master: Fast-forward
cde**7c HEAD@{9}: reset: moving to HEAD
cde**7c HEAD@{10}: pull origin master: Fast-forward
389**09 HEAD@{11}: reset: moving to HEAD^^^
d02**f9 HEAD@{12}: reset: moving to HEAD^^
912**c7 HEAD@{13}: reset: moving to HEAD^

Then you can reset to some version by using:

get reset HASH

Tip2 - What if we don’t want some of the submitted records?

Sometimes you may do these things:

$ git add ./
$ git commit -m "add a new module of part 233" # add 982 lines
$ git add ./.../..
$ git commit -m "fix bug2, f**ck, sh**t !"  # add 162 lines, wrong changes, no need
$ git add ./.../..
$ git commit -m "fix some bugs"  # add 34 lines, This is the right changes
$ git add ./../
$ git commit -m "add a new module of part 243"  # add 378 lines

Because of your upsetting bugs, accidentally leaving a few swear words on the git commit, but this interspersed in the commit record, what should you do?

  • add a temp branch
git branch temp
  • paste some logs of commits to the editor
git log # copy text to editor from LATEST commit start to commit end
  • reset commits
git reset HASH # to the "add a new module of part 233" one
  • chose some commits to recover
git cherry-pick HASH1
git cherry-pick HASH2
....

Finally, the record you don’t need will disappear in your current version.

Tip3 - Some individuals use notes

The following content is some personal notes I recorded

Type Command String Test Introduction
Config git config –global user.name “[name]” PASS Sets the name you want attached to your commit transactions
git config –global user.email “[email address]” PASS Sets the email you want attached to your commit transactions
Init git init [project-name] PASS Creates a new local repository with the specified name
git clone [url] PASS Downloads a project and its entire version history
CHANGES git status PASS Lists all new or modified files to be committed
git diff PASS Shows file differences not yet staged
git add [file] PASS Snapshots the file in preparation for versioning(. means all files)
git diff –staged PASS Shows file differences between staging and the last file version
git reset [file] PASS Unstages the file, but preserve its contents
git commit -m “[descriptive message]” PASS Records file snapshots permanently in version history
Branch git branch PASS Lists all local branches in the current repository
git branch [branch-name] PASS Creates a new branch
git checkout [branch-name] PASS Switches to the specified branch and updates the working directory
git merge [branch] PASS Combines the specified branch’s history into the current branch
git branch -d [branch-name] PASS Deletes the specified branch
REFACTOR git rm [file] PASS Deletes the file from the working directory and stages the deletion
git rm –cached [file] PASS Removes the file from version control but preserves the file locally
git mv [file-original] [file-renamed] PASS Changes the file name and prepares it for commit
TRACKING git ls-files –other –ignored –exclude-standard PASS Lists all ignored files in this project
SAVE FRAGMENTS git stash PASS Temporarily stores all modified tracked files
git stash pop PASS Restores the most recently stashed files
git stash list PASS Lists all stashed changesets
git stash drop PASS Discards the most recently stashed changeset
SYNCHRONIZE CHANGES git fetch [bookmark] PASS Downloads all history from the repository bookmark
git merge [bookmark]/[branch] PASS Combines bookmark’s branch into current local branch
git push [alias] [branch] PASS Uploads all local branch commits to GitHub
git pull [remote] [branch] PASS Downloads bookmark history and incorporates changes

Tip4 - Set multi github account in One PC

1.Open the git bash and input the codes:

 ssh-keygen -t rsa -b 4096 -C "shinepans@live.com (Your Email)"

And it outcomes:

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/shinepans/.ssh/id_rsa): id_rsa_cess (id_rsa_cess:We need to create a new name that is different from the previous file name )

And it outcomes:

Enter passphrase (empty for no passphrase): (Enter)
Enter same passphrase again:(Enter)
Your identification has been saved in id_rsa_cess.
Your public key has been saved in id_rsa_cess.pub.
The key fingerprint is:
SHA256:jgkhEZIjeQNF6CZWU+sIpCUbZBIip+AdgQcZlnXlon0 shinepans@live.com
The key's randomart image is:
+---[RSA 4096]----+
|%/#=oo.. |
|^%+=o o          |
|*=+ooo .         |
|.+..=..          |
|+  o.o ES        |
|     ..+         |
|      o .        |
|                 |
|                 |
+----[SHA256]-----+

2.Configure the ~/.ssh/config file

Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa
Host cess.github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_cess

2.Add the new generated SSH key to the associated Github account

Add the newly generated key in id_rsa_cess.pub to the associated Github account.

And Then Use

$ ssh -T git@cess.github.com

to test whether the association is successful. The xxx.github.com used here is the name of the second host in the previous config.

And it should be outcomes:

$ Hi cessuser! You've successfully authenticated, but GitHub does not provide shell access.

3.Use multiple SSH Key

If we need use default account whose ssh key is id_ras.pub, we can use

git clone git@github.com:USER/SOMETHING.git

If we need use another account whose ssh key is id_ras_cess.pub, we can use

“`
git clone git@cess.github.com:USER/SOMETHING.git


推荐阅读
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • 花瓣|目标值_Compose 动画边学边做夏日彩虹
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了Compose动画边学边做-夏日彩虹相关的知识,希望对你有一定的参考价值。引言Comp ... [详细]
  • 生成式对抗网络模型综述摘要生成式对抗网络模型(GAN)是基于深度学习的一种强大的生成模型,可以应用于计算机视觉、自然语言处理、半监督学习等重要领域。生成式对抗网络 ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • ZSI.generate.Wsdl2PythonError: unsupported local simpleType restriction ... [详细]
  • sklearn数据集库中的常用数据集类型介绍
    本文介绍了sklearn数据集库中常用的数据集类型,包括玩具数据集和样本生成器。其中详细介绍了波士顿房价数据集,包含了波士顿506处房屋的13种不同特征以及房屋价格,适用于回归任务。 ... [详细]
  • 本文介绍了Web学习历程记录中关于Tomcat的基本概念和配置。首先解释了Web静态Web资源和动态Web资源的概念,以及C/S架构和B/S架构的区别。然后介绍了常见的Web服务器,包括Weblogic、WebSphere和Tomcat。接着详细讲解了Tomcat的虚拟主机、web应用和虚拟路径映射的概念和配置过程。最后简要介绍了http协议的作用。本文内容详实,适合初学者了解Tomcat的基础知识。 ... [详细]
  • 在重复造轮子的情况下用ProxyServlet反向代理来减少工作量
    像不少公司内部不同团队都会自己研发自己工具产品,当各个产品逐渐成熟,到达了一定的发展瓶颈,同时每个产品都有着自己的入口,用户 ... [详细]
  • OrbitDBPeer 2 Peer Database using CRDTs
    2019独角兽企业重金招聘Python工程师标准Apeer-to-peerdatabaseforthedecentralizedwebOrbitDBisaserverless ... [详细]
author-avatar
13888102467波光_1984
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有