git和github

安装GIT

  sudo apt-get install git

  [root@s1-61526 /]# git --version                                                                     
    git version 1.7.1                                                                                    
  [root@s1-61526 /]# 
 


 

初始化一个Git仓库,使用git init命令。

添加文件到Git仓库,分两步:

  • 第一步,使用命令git add <file>,注意,可反复多次使用,添加多个文件;

  • 第二步,使用命令git commit,完成。

  • 如下:
复制代码
[root@s1-61526 git_trainning]# ls                                                                    
first_git.txt                                                                                        
[root@s1-61526 git_trainning]#                                                                       
[root@s1-61526 git_trainning]# vim file1.txt                                                         
[root@s1-61526 git_trainning]# git add file1.txt                                                     
[root@s1-61526 git_trainning]# git commit -m "add file1.txt"                                         
[master e855407] add file1.txt                                                                       
 Committer: root <root@s1-61526.(none)>                                                              
Your name and email address were configured automatically based                                      
on your username and hostname. Please check that they are accurate.                                  
You can suppress this message by setting them explicitly:                                            
                                                                                                     
    git config --global user.name "Your Name"                                                        
    git config --global user.email you@example.com                                                   
                                                                                                     
If the identity used for this commit is wrong, you can fix it with:                                  
                                                                                                     
    git commit --amend --author='Your Name <you@example.com>'                                        
                                                                                                     
 1 files changed, 1 insertions(+), 0 deletions(-)                                                    
 create mode 100644 file1.txt                                                                        
[root@s1-61526 git_trainning]#                   
复制代码

 

git status

  • 要随时掌握工作区的状态,使用git status命令。

  • 如果git status告诉你有文件被修改过,用git diff可以查看修改内容。

  • 例如,对file1.txt做了修改后,可以通过diff命令查看具体修改的内容,如下:
复制代码
git diff file1.txt

diff
--git a/file1.txt b/file1.txt index e212970..582e430 100644 --- a/file1.txt +++ b/file1.txt @@ -1 +1,3 @@ file1 +Git is a distributed version control system. +Git is free software. [root@s1-61526 git_trainning]# [root@s1-61526 git_trainning]# git add file1.txt [root@s1-61526 git_trainning]# git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: file1.txt # [root@s1-61526 git_trainning]# git commit -m "add distributed" [master b70b785] add distributed 1 files changed, 2 insertions(+), 0 deletions(-) [root@s1-61526 git_trainning]# git status # On branch master nothing to commit (working directory clean) [root@s1-61526 git_trainning]#
复制代码

 

查看更新的版本

复制代码
$ git log
commit 132b65ebbc959887f3dceda9342692b85cc0cbd6
Author: ligq <noube@qq.com>
Date:   Thu Mar 9 20:05:38 2017 +0800

    hoho

commit ac3de534b8e82e5d98734f5e2dda2b6c54694c85
Author: ligq <noube@qq.com>
Date:   Thu Mar 9 20:02:35 2017 +0800

    forgive me

commit ba084157d3b74b044c29c79116c079bc72d5322a
Author: ligq <noube@qq.com>
Date:   Thu Mar 9 19:54:33 2017 +0800

    test

commit 0388642f31eaf542228c9d7f22b1dbc2aa48b708
Author: ligq <noube@qq.com>
Date:   Thu Mar 9 19:53:02 2017 +0800

    first using git

ligq@DESKTOP-4SLI49M MINGW64 ~/git_trainning (master)
$
普通方式
复制代码
ligq@DESKTOP-4SLI49M MINGW64 ~/git_trainning (master)
$ git log --pretty=oneline
132b65ebbc959887f3dceda9342692b85cc0cbd6 hoho
ac3de534b8e82e5d98734f5e2dda2b6c54694c85 forgive me
ba084157d3b74b044c29c79116c079bc72d5322a test
0388642f31eaf542228c9d7f22b1dbc2aa48b708 first using git

ligq@DESKTOP-4SLI49M MINGW64 ~/git_trainning (master)

 

回滚

#回滚到指定版本
$ git reset --hard 132b65e
HEAD is now at 132b65e hoho

#回滚到上一个版本
$ git reset --hard HEAD^
HEAD is now at 0388642 first using git

 

posted @   noube  阅读(218)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
点击右上角即可分享
微信分享提示