IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 开发工具 -> Git: Basic Workflow and Commands -> 正文阅读

[开发工具]Git: Basic Workflow and Commands

Entry-Level Tutorial

from: Learn the Basics of Git in Under 10 Minutes

more comprehensive:?Basic Git Commands With Examples "git add . or git add -A" [Git Cheat Sheet]

Start A Depo

from: Git - Getting a Git Repository

key:

(build from local file) init, add, commit;

clone

==> clone is a convenient command (init, add, fetch, checkout), see?Do I need to do 'git init' before doing 'git clone' on a project

==> most often requires credential by?SSH or HTTPS see example at:?Connecting to GitHub with SSH - GitHub Docs

Local Temporary Branch by?stash:?

from: What is git stash?

Git stash?is a built-in command with the distributed Version control tool in?Git?that locally stores all the most recent changes in a workspace and resets the state of the workspace to the prior commit state.

A user can retrieve all files put into the stash with the?git stash pop?and?git stash apply?commands.?Git stash?acts as a mechanism to locally [store] version files without those versions being seen by other developers who share the same git repository.

Overwrite Local Files

from: How do I force "git pull" to overwrite local files?

? Important: If you have any local changes, they will be lost. With or without?--hard?option, any local commits that haven't been pushed will be lost.[*]

If you have any files that are?not?tracked by Git (e.g. uploaded user content), these files will not be affected.


First, run a fetch to update all?origin/<branch>?refs to latest:

git fetch --all

Backup your current branch:

git branch backup-master

Then, you have two options:

git reset --hard origin/master

OR If you are on some other branch:

git reset --hard origin/<branch_name>

?==> normally we commit (sync)?or stash (backup)?all changes then pull newly added files from the remote depo.

Branch and Checkout

from: Git Branch | Atlassian Git Tutorial

?Branching is a feature available in most modern version control systems. Branching in other VCS's can be an expensive operation in both time and disk space. In Git, branches are a part of your everyday development process. Git branches are effectively a pointer to a snapshot of your changes. When you want to add a new feature or fix a bug—no matter how big or how small—you spawn a new branch to encapsulate your changes. This makes it harder for unstable code to get merged into the main code base, and it gives you the chance to clean up your future's history before merging it into the main branch.

????????????????

The diagram above visualizes a repository with two isolated lines of development, one for a little feature, and one for a longer-running feature. By developing them in branches, it’s not only possible to work on both of them in parallel, but it also keeps the?main?branch free from questionable code.

The implementation behind Git branches is much more lightweight than other version control system models. Instead of copying files from directory to directory, Git stores a branch as a reference to a commit. In this sense, a branch represents the tip of a series of commits—it's not a container for commits. The history for a branch is extrapolated through the commit relationships.

for more, see the tutorial for usage and?Git - git-branch Documentation

from:?Git Checkout | Atlassian Git Tutorial

Git checkout?works hand-in-hand with?git branch. The?git branch?command can be used to create a new branch. When you want to start a new feature, you create a new branch off?main?using?git branch new_branch. Once created you can then use?git checkout new_branch?to switch to that branch. Additionally, The?git checkout?command accepts a?-b?argument that acts as a convenience method which will create the new branch and immediately switch to it. You can work on multiple features in a single repository by switching between them with?git checkout.

git?checkout?-b?<new-branch>

The above example simultaneously creates and checks out?. The?-b?option is a convenience flag that tells Git to run?git branch?before running?git checkout.

git?checkout?-b?<new-branch>?<existing-branch>

By default?git checkout -b?will base the?new-branch?off the current?HEAD. An optional additional branch parameter can be passed to?git checkout. In the above example,?existing-branch>?is passed which then bases?new-branch?off of?existing-branch?instead of the current?HEAD.

Rebase

from:?git rebase | Atlassian Git Tutorial

Rebase is one of two Git utilities that specializes in integrating changes from one branch onto another. The other change integration utility is?git merge. Merge is always a forward moving change record. Alternatively, rebase has powerful history rewriting features. For a detailed look at Merge vs. Rebase, visit our?Merging vs Rebasing guide. Rebase itself has 2 main modes: "manual" and "interactive" mode. We will cover the different Rebase modes in more detail below.

What is git rebase?

Rebasing is the process of moving or combining a sequence of commits to a new base commit. Rebasing is most useful and easily visualized in the context of a feature branching workflow. The general process can be visualized as the following:

From a content perspective, rebasing is changing the base of your branch from one commit to another making it appear as if you'd created your branch from a different commit. Internally, Git accomplishes this by creating new commits and applying them to the specified base. It's very important to understand that even though the branch looks the same, it's composed of entirely new commits.

Usage

The primary reason for rebasing is to maintain a linear project history. For example, consider a situation where the main?branch has progressed since you started working on a feature branch. You want to get the latest updates to the main?branch in your feature branch, but you want to keep your branch's history clean so it appears as if you've been working off the latest main?branch. This gives the later benefit of a clean merge of your feature branch back into the main?branch. Why do we want to maintain a "clean history"? The benefits of having a clean history become tangible when performing Git operations to investigate the introduction of a regression. A more real-world scenario would be:

  1. A bug is identified in the main?branch. A feature that was working successfully is now broken.
  2. A developer examines the history of the main branch using?git log?because of the "clean history" the developer is quickly able to reason about the history of the project.
  3. The developer can not identify when the bug was introduced using?git log?so the developer executes a?git bisect.
  4. Because the git history is clean,?git bisect?has a refined set of commits to compare when looking for the regression. The developer quickly finds the commit that introduced the bug and is able to act accordingly.

Learn more about?git log?and?git bisect?on their individual usage pages.

You have two options for integrating your feature into the main?branch: merging directly or rebasing and then merging. The former option results in a 3-way merge and a merge commit, while the latter results in a fast-forward merge and a perfectly linear history. The following diagram demonstrates how rebasing onto the main?branch facilitates a fast-forward merge.

(see:?What is a fast-forward merge in Git?

"Fast forward merge can be performed when there is a direct linear path from the source branch to the target branch. In fast-forward merge, git simply moves the source branch pointer to the target branch pointer without creating an extra merge commit.")

???????????????????????

Rebasing is a common way to integrate upstream changes into your local repository. Pulling in upstream changes with Git merge results in a superfluous merge commit every time you want to see how the project has progressed. On the other hand, rebasing is like saying, “I want to base my changes on what everybody has already done.”

Don't rebase public history

As we've discussed previously in?rewriting history, you should never rebase commits once they've been pushed to a public repository. The rebase would replace the old commits with new ones and it would look like that part of your project history abruptly vanished.

  开发工具 最新文章
Postman接口测试之Mock快速入门
ASCII码空格替换查表_最全ASCII码对照表0-2
如何使用 ssh 建立 socks 代理
Typora配合PicGo阿里云图床配置
SoapUI、Jmeter、Postman三种接口测试工具的
github用相对路径显示图片_GitHub 中 readm
Windows编译g2o及其g2o viewer
解决jupyter notebook无法连接/ jupyter连接
Git恢复到之前版本
VScode常用快捷键
上一篇文章      下一篇文章      查看所有文章
加:2021-11-26 09:03:29  更:2021-11-26 09:05:07 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/15 19:56:04-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码