blog
blog copied to clipboard
Git Commands versus SVN Commands
Git is a distributed version control system (DVCS) and SVN (Subversion) is a centralized version control system (CVCS), their commands differ in many ways, but both serve similar fundamental purposes in managing versions of code.
Here's a comparison of some of the common Git commands versus their equivalents or similar commands in SVN.
1. Repository Creation & Cloning
Task | Git Command | SVN Command |
---|---|---|
Create a repository (locally) | git init |
svnadmin create /path/to/repository |
Clone a repository (copy) | git clone <repository-url> |
svn checkout <repository-url> |
Explanation:
Git's git init
creates a local repository, while in SVN, svnadmin create
initializes a repository on the server. Cloning (copying a remote repository) is handled by git clone
in Git and svn checkout
in SVN.
2. Adding and Removing Files
Task | Git Command | SVN Command |
---|---|---|
Add a file to be tracked | git add <file> |
svn add <file> |
Remove a file | git rm <file> |
svn delete <file> |
Explanation:
Both Git and SVN require adding files before tracking them. However, in Git, you must explicitly add changes to the staging area before committing, while SVN tracks changes automatically upon commit.
3. Committing Changes
Task | Git Command | SVN Command |
---|---|---|
Commit changes | git commit -m "message" |
svn commit -m "message" |
Commit all tracked changes | git commit -a -m "message" |
Not necessary in SVN |
Explanation:
In Git, you need to stage changes before committing, while SVN automatically includes all changes in the working directory during the commit process.
4. Checking Status and Logs
Task | Git Command | SVN Command |
---|---|---|
Check status of working directory | git status |
svn status |
View commit history | git log |
svn log |
Explanation:
Both Git and SVN have equivalent commands to check the working directory's status (git status
vs svn status
) and to view the commit history (git log
vs svn log
).
5. Branching and Merging
Task | Git Command | SVN Command |
---|---|---|
Create a new branch | git branch <branchname> |
svn copy <trunk_url> <branch_url> |
Switch to a branch | git checkout <branchname> |
svn switch <branch_url> |
Merge branches | git merge <branchname> |
svn merge <branch_url> |
Explanation:
Git's branching is more lightweight and faster than SVN’s, as it uses git branch
and git checkout
. SVN branches are created using the svn copy
command, and switching to a branch is done with svn switch
.
6. Syncing with Remote Repository
Task | Git Command | SVN Command |
---|---|---|
Pull changes from the remote repository | git pull |
svn update |
Push changes to the remote repository | git push |
Not applicable (SVN commits directly to the central repo) |
Explanation:
Git requires git pull
to fetch and merge changes from the remote repository, while SVN uses svn update
. In Git, git push
sends local changes to the remote repository. SVN commits directly to the central repository, so there's no equivalent to git push
.
7. Viewing Differences (Diffs)
Task | Git Command | SVN Command |
---|---|---|
View changes in working directory | git diff |
svn diff |
Compare two commits (revisions) | git diff <commit1> <commit2> |
svn diff -r <revision1>:<revision2> |
Explanation:
Both systems provide diff
commands to see changes between versions of files or in the working directory.
8. Reverting Changes
Task | Git Command | SVN Command |
---|---|---|
Undo changes in the working directory | git checkout -- <file> |
svn revert <file> |
Revert to a previous commit (revision) | git reset --hard <commit> |
svn merge -r HEAD:<revision> <path> |
Explanation:
In Git, git checkout
reverts uncommitted changes, while git reset
can undo commits. In SVN, svn revert
undoes changes in the working directory, and svn merge
can be used to roll back to a previous revision.
9. Tagging a Version
Task | Git Command | SVN Command |
---|---|---|
Create a tag | git tag <tagname> |
svn copy <trunk_url> <tag_url> |
Explanation:
Git uses git tag
to mark specific points in history as being important. In SVN, tags are created by copying the trunk to a new URL, which is a virtual equivalent of a tag.
10. Inspecting Remote Repositories
Task | Git Command | SVN Command |
---|---|---|
Show remote repository details | git remote -v |
svn info |
Explanation:
git remote -v
shows the URL of the remote repositories in Git, while svn info
gives detailed information about the SVN repository and working copy.
11. Handling Conflicts
Task | Git Command | SVN Command |
---|---|---|
Resolve merge conflicts | git mergetool |
svn resolve |
Explanation:
Both Git and SVN have tools for resolving conflicts that arise when merging changes. Git uses git mergetool
for manual conflict resolution, while SVN uses svn resolve
.
12. Ignoring Files
Task | Git Command | SVN Command |
---|---|---|
Ignore untracked files | Create a .gitignore file |
Set svn:ignore property |
Explanation:
In Git, you create a .gitignore
file to list the files or directories you want to ignore. In SVN, you use the svn:ignore
property to achieve the same effect.
Summary Table
Action | Git | SVN |
---|---|---|
Create repository | git init |
svnadmin create |
Clone repository | git clone |
svn checkout |
Add files | git add |
svn add |
Remove files | git rm |
svn delete |
Commit changes | git commit |
svn commit |
Check status | git status |
svn status |
Log history | git log |
svn log |
Branching | git branch |
svn copy |
Switch branch | git checkout |
svn switch |
Merge branches | git merge |
svn merge |
Pull changes | git pull |
svn update |
Push changes | git push |
N/A (SVN commits directly) |
Diff changes | git diff |
svn diff |
Undo changes | git checkout , git reset |
svn revert , svn merge |
Tag a version | git tag |
svn copy (for tags) |
Resolve conflicts | git mergetool |
svn resolve |
Ignore files | .gitignore |
`svn |