git 常用的东西!

Last login: Fri Mar 18 04:35:35 on ttys000

bogon:~ mac$ git config --global user.name "梦想之树"

bogon:~ mac$ git config --global user.email "960462916@qq.com"

bogon:~ mac$ cd /Users/mac/Documents/zhanxin/code

bogon:code mac$ git clone https://git.oschina.net/dreamsuccess/zhanxin.git

Cloning into 'zhanxin'...

remote: Counting objects: 3, done.

remote: Total 3 (delta 0), reused 0 (delta 0)

Unpacking objects: 100% (3/3), done.

Checking connectivity... done.

bogon:code mac$ git commit -am "删除文件"

fatal: Not a git repository (or any of the parent directories): .git

bogon:code mac$ git commit -am "ddd"

fatal: Not a git repository (or any of the parent directories): .git

bogon:code mac$ ls

zhanxin

bogon:code mac$ cd zhanxin

bogon:zhanxin mac$ git commit -am "删除文件"

[master a21c429] 删除文件

 1 file changed, 1 deletion(-)

 delete mode 100644 README.md

bogon:zhanxin mac$ git commit -am "添加文件"

On branch master

Your branch is ahead of 'origin/master' by 1 commit.

  (use "git push" topublish your local commits)

Untracked files:

    .DS_Store

    zhanxin.xcodeproj/

    zhanxin/

    zhanxinTests/

    zhanxinUITests/

 

nothing added to commit but untracked files present

bogon:zhanxin mac$ git push origin master

Counting objects: 2, done.

Writing objects: 100% (2/2), 217 bytes | 0 bytes/s, done.

Total 2 (delta 0), reused 0 (delta 0)

To https://git.oschina.net/dreamsuccess/zhanxin.git

   f1f1883..a21c429  master -> master

bogon:zhanxin mac$ git pull

Already up-to-date.

bogon:zhanxin mac$ git add .

bogon:zhanxin mac$ git commit -am "新建工程"

[master a7adea8] 新建工程

 19 files changed, 1085insertions(+)

 create mode 100644 .DS_Store

 create mode 100644zhanxin.xcodeproj/project.pbxproj

 create mode 100644zhanxin.xcodeproj/project.xcworkspace/contents.xcworkspacedata

 create mode 100644zhanxin.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate

 create mode 100644zhanxin.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist

 create mode 100644zhanxin.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/zhanxin.xcscheme

 create mode 100644zhanxin/AppDelegate.h

 create mode 100644zhanxin/AppDelegate.m

 create mode 100644zhanxin/Assets.xcassets/AppIcon.appiconset/Contents.json

 create mode 100644zhanxin/Base.lproj/LaunchScreen.storyboard

 create mode 100644zhanxin/Base.lproj/Main.storyboard

 create mode 100644zhanxin/Info.plist

 create mode 100644zhanxin/ViewController.h

 create mode 100644zhanxin/ViewController.m

 create mode 100644 zhanxin/main.m

 create mode 100644zhanxinTests/Info.plist

 create mode 100644zhanxinTests/zhanxinTests.m

 create mode 100644zhanxinUITests/Info.plist

 create mode 100644zhanxinUITests/zhanxinUITests.m

bogon:zhanxin mac$ git push origin master

Counting objects: 33, done.

Delta compression using up to 4 threads.

Compressing objects: 100% (28/28), done.

Writing objects: 100% (33/33), 16.86 KiB | 0 bytes/s, done.

Total 33 (delta 1), reused 0 (delta 0)

To https://git.oschina.net/dreamsuccess/zhanxin.git

   a21c429..a7adea8  master -> master

bogon:zhanxin mac$ 

### Git 常用命令汇总 以下是 Git 的一些常用命令及其功能说明: #### 本地操作 - **初始化仓库** 使用 `git init` 初始化一个新的 Git 版本库[^1]。 - **查看状态** 使用 `git status` 查看当前工作区的状态,了解哪些文件被修改或未跟踪[^2]。 - **添加文件到暂存区** 使用 `git add <file>` 或者 `git add .` 将指定文件或者全部改动加入到暂存区。 - **提交更改到本地库** 使用 `git commit -m "message"` 提交代码到本地库,并附带一条提交信息。如果需要同时完成 `add` 和 `commit` 操作,可使用 `git commit -a -m "message"`[^1]。 - **修正最近的一次提交** 如果发现刚刚的提交有误,可以通过 `git commit --amend` 修改最后一次提交的内容。 #### 文件管理 - **移除文件** 当需要从版本控制中删除某个文件时,可以使用 `git rm <file>` 删除该文件并将其变动记录到下次提交中[^2]。 - **恢复已修改但尚未提交的文件** 若不小心修改了某些文件而希望撤销这些修改,可以运行 `git checkout -- <filename>` 来还原文件至上次提交的状态。注意此操作不会影响已经通过 `git add` 加入暂存区的变化[^2]。 - **重命名文件** 可以利用 `git mv oldname newname` 对文件进行更名处理,这相当于先执行了一次移动再加一次添加动作[^3]。 #### 远程同步 - **关联远程仓库** 执行 `git remote add origin <url>` 设置一个名为 “origin” 的远端地址指向目标服务器上的项目位置[^4]。 - **推送数据到远程仓库** 要将本地分支推送到远程服务器上对应的分支,可以用如下形式调用:`git push [-u] origin branchName` 。其中 `-u` 参数表示设置上游分支以便后续简化为仅需输入 `git push` 即可实现相同效果。 - **拉取最新变更** 若要获取来自其他开发者的新贡献并与自己的副本合并起来,则应该采用 `git pull [--rebase] origin branchName` 方法来达成目的;另外还有一种方式叫做 rebase ,它能够使历史更加整洁有序[^3][^4]。 - **克隆现有存储库** 新建目录并通过复制一份完整的拷贝开始合作流程的话,那么就应当运用这样的语法结构来进行操作——即 `git clone url destinationPath`。 ```bash # 示例代码片段展示如何实际应用上述部分命令 $ git init myProject # 创建新repo Initialized empty Git repository in /path/to/myProject/.git/ $ cd !$ # 移动进入新建好的文件夹 cd myProject $ echo "# Test Project" >> README.md # 向readme里追加内容作为测试素材 $ git add README.md # 把新增的东西标记出来准备提交 $ git commit -m "first commit" # 正式保存这次改变 [master (root-commit) e0f8c9b] first commit 1 file changed, 1 insertion(+) create mode 100644 README.md ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值