git_ask_00-From SVN to Git

ID = git_ask_00

Question

How to run SVN operation in Git?

Answer

Most SVN operation can be reflected in Git

SVNGit
checkoutgit clone
updategit pull
check for modificationgit diff HEAD
addgit add
undo addgit restore
deletegit rm
N/Agit commit
commitgit push
show loggit log, git reflog
revertgit reset
comparegit diff
revisioncommit-id or hash-id
trunkbranch master
N/Aworking tree
N/Aindex tree
working copyHEAD tree

Follow the following procedure to make it.

Step1: Create project in Github

This is similar to create repository in SVN.
Later, we can checkout in local.

Step2: Checkout

This operation is used to copy a project from server to local

SVN Export operation

git clone _address_in_github_

Step3: Update

SVN Update operation

git pull

Make sure, every time when you are going to do modification, you working copy is the newest after synchronizing with the server

$ git pull

Already up to date.

The following command can be used to get current status of server:

git remote -v
git fetch origin master
git log -p  master.. origin/master

Reference:
git 更新远程代码到本地仓库

Step4: Add changes to Index

Different from SVN, changes are needed to transfer to Index at first.

git add _filename_

git add *

git add . 会把本地所有untrack的文件都加入暂存区,并且会根据.gitignore做过滤,但是git add * 会忽略.gitignore把任何文件都加入

Step5: Commit

git commit -m "notes"

Now you changes are in HEAD now.

Step6: Conflict resolve manually

Run git pull again to make sure there is no conflict before push to server.

If there is any conflict, use VS Code to resolve manually.

And after resolved, need to add new file again and commit again.

How to resolve conflict?

Type git status to watch conflict detais

如何解决在使用git pull 拉取线上代码时发生的冲突

手动打开文件后会发现,代码会被<<<<<<<<<、==、 >>>>>>>>>等包围,这是冲突标记。关于冲突标记:<<<<<<和之间的内容是本地自己修改的,========与>>>>>>>>>之间的内容是别人修改的。

Step7: Push to server

git push origin master

You can also change master to any branch you want.

If you haven’t cloned before, you need to link your current project to server by the following command:

git remote add origin <server>

Q&A

Q1. git Bash Here?

A1 It is an operation, git bash here, git is tool, bash is action, here is current directory.

Therefore, the final resut will be:
Open command terminal and change directory to your current folder.

Q2. How to add folder?

Add folder in your working directory.
Then, git add ., and then go to commit and push process.

Q3. How to show log?

For more detail, need to learn this set of command git log, such as,

git log FETCH_HEAD
git log origin/master

Q4. How to compare?

For more detail, need to learn this set of command git diff

Reference

[1] git 更新远程代码到本地仓库

[2] https://blog.csdn.net/weixin_36564655/article/details/89682393

[3] 如何解决在使用git pull 拉取线上代码时发生的冲突

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
execute_process(COMMAND sh -c "git symbolic-ref --short -q HEAD" OUTPUT_VARIABLE GIT_BRANCH OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND sh -c "git rev-list HEAD --abbrev=8 --abbrev-commit --max-count=1" OUTPUT_VARIABLE GIT_LAST_COMMIT OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND sh -c "git rev-list HEAD --count" OUTPUT_VARIABLE GIT_COMMITS_NUM OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND sh -c "git status --short --untracked-files=no | wc -l" OUTPUT_VARIABLE GIT_DIFF_STATUS OUTPUT_STRIP_TRAILING_WHITESPACE) if ( ${GIT_DIFF_STATUS} EQUAL "0" ) set(BUILD_VERSION "R${GIT_LAST_COMMIT}_${GIT_BRANCH}") else() set(BUILD_VERSION "R${GIT_LAST_COMMIT}M_${GIT_BRANCH}") endif() #build date string(TIMESTAMP DATETIME "%Y%m%d%H%M%S") #enable gdb debug symbol if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release") message (STATUS "No CMAKE_BUILD_TYPE selected, defaulting to ${CMAKE_BUILD_TYPE}") endif() message (STATUS "The CMAKE_BUILD_TYPE is selected to ${CMAKE_BUILD_TYPE}") set(CMAKE_CXX_FLAGS_BASE "$ENV{CXXFLAGS} -pipe -Wall -Wno-unknown-pragmas -Wno-format-zero-length -lrt -Wno-ignored-attributes") #set(CMAKE_CXX_FLAGS_BASE "${CMAKE_CXX_FLAGS_BASE} -save-temps") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_BASE} -O2 -g") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_BASE} -O3") #set(CMAKE_DEBUG_POSTFIX _D) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time") set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CMAKE_COMMAND} -E time")
07-22

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值