文章目录
ID = git_ask_00
Question
How to run SVN operation in Git?
Answer
Most SVN operation can be reflected in Git
SVN | Git |
---|---|
checkout | git clone |
update | git pull |
check for modification | git diff HEAD |
add | git add |
undo add | git restore |
delete | git rm |
N/A | git commit |
commit | git push |
show log | git log, git reflog |
revert | git reset |
compare | git diff |
revision | commit-id or hash-id |
trunk | branch master |
N/A | working tree |
N/A | index tree |
working copy | HEAD 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
手动打开文件后会发现,代码会被<<<<<<<<<、==、 >>>>>>>>>等包围,这是冲突标记。关于冲突标记:<<<<<<和之间的内容是本地自己修改的,========与>>>>>>>>>之间的内容是别人修改的。
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