Source Control

Jump to:

                                centralized scm                 distributed scm
                                =============================   ====================================
task:  			     	svn		rcs		git 			hg/mercurial	
-----------------------------   --------------- -------------   ----------------------- -------------
update repo:			up		co?
check out			co 		co		clone			clone
                                                                checkout tags/2.2
lock file for edit		not needed?	co -l		not needed
check in			ci		ci		commit -a, push	

what has changed?		status				status
diff b/w current and repo:	diff		rcsdiff		diff			diff
change list:			log		rcs log		log --oneline

git (and mercurial hg) is a distributed source control system. Traditional scm like svn, cvs, p4, rcs, are centralized system and has a single primary repo. git has a very different mode operandi than the traditional system, thus the table of "equivalent" commands above is somewhat misleading. RTFM!! =)

SVN Subversion commands

svn checkout http://svn-server/path/to/project	localDirName
	# download all files related to a svn project/repo
	# storing all files in a subfolder called "localDirName"
	# .svn/entries should have the URL of the source

svn info	# tell where svn tree source info
svn add  file	# add a file into svn repo  (this auto check in the file??)
svn mkdir foo	# create a new dir and have it added to repo (after ci)

svn ci 			# check in, ie, commit changes into svn
svn ci file1 file2	# check in only specified file(s).  note that removing entry in the comment window does NOT remove the file from being commited!!		


svn diff file		# diff b/w working copy and last version in repo
svn diff file		# diff b/w working copy and last version in repo


proxy settings.  Unfortunately don't seems to have a cli method to change it.  
playing with exceptions maybe the trick.
it does NOT heed environment variable http_proxy
edit $HOME/.subversion/server 
in the global section, there are several proxy clauses, eg
###   http-proxy-host            Proxy host for HTTP connection$
###   http-proxy-port            Port number of proxy host service$
###   http-proxy-username        Username for auth to proxy service$
###   http-proxy-password        Password for auth to proxy service$
###   http-proxy-exceptions      List of sites that do not use proxy$

If cached password has been changed, 
rm ~/.subversion/auth
(caching password is not recommended, svn does warn that it is not secure... 
but didn't see cleartext password stored there, 
maybe is is simple obfuscation rather than real encryption.  
and file could be copied... )


--
svnadmin create		# these are admin commands, such as create a new svn repository.

Granting user read (r) or read/write (rw) access to a svn repo, edit 
	/etc/opt/CollabNet_Subversion/conf/svn_access_file
be careful with typo.  a single mistake will render the file unparseable and no one would be able to use svn !!



--
svnlook info somerepo		# these will look at a repo w/o checking it out
svnlook log  somerepo
svnlook tree somerepo


--
Tortoise SVN is a simple, lightweight SVN client avail in windows.


cvs

$CVSROOT                the source dir
$PROJROOT               the local dir where copy of cvs is placed, this is the
edit place till changes are commited

so far, only successful by checking out files while pwd=$PROJROOT, and then spe
cify full path for file.  if just specify dir name, the whole sub dir is checke
d out

cvs co dir/filename     check out file
cvs add                 add file to c vs tree
cvs commit              make changes permanenet

perforce



if submit has problems, can do:

p4 revert -a    = revert files that have not been edited (no changes)
                                  very useful after accidental p4 edit ... !!!
p4 revert               = note, old changes to file will be DELETED.
p4 change -d {change#}  = remove change request

p4 changes -m100        = check for list of changes, use grep to find my own.  (-m100 show last 100 changes only.  the cmd shows all historical data).


to sync files in selected dir only.
cd to the desired dir, then do:
p4 sync ...

or, pf sync /path/to/dir/...
the '...' indicate the 'files in this position at the depot'.

sync against a known date/time

p4 sync ...@"2002/06/22 00:01"
Time can be omitted, it will default to the beginning of that date (not the end!)

sync against a label?


p4 diff FILE
the entries marked by '<' is my own file
and those in '>' is the file in p4

(diff file1 file2, < is left file1, > is right file2, so I guess p4 diff check
out a file as temp and use that as file2).

p4 diff FILE#1 FILE#3
compare version 1 and 3 of FILE

p4 sync -n ...          # just see changes for current dir
p4 sync -f ...          # force all update on current dir (only force refresh of
files not checked out, as in refresh accidental removal of non locked file.
those that have been updated remains open, no accidental erasure cuz of
refresh )

p4 opened ...           # list of files opened
p4 edit {file}          # open a file for editing

p4 branches                     # list p4 branches that can be added to client view.

p4 log... ?             # see revision history of file



zmbl stuff?
p4rename        : script to rename a file checked into P4.

-t {FILETYPE}
   FILETYPE one of symlink, etc

change file to executable
p4 edit -t kxtext FILE
p4 submit

git

git is a very different beast than the other traditional source control system. Instead of having a "code centric" view to create trees and branches, git is more of a "developer centric" paradigm. As such, many actions don't have the same parallel as say SVN, even though some commands seems similar on the surface.
git works as a two stage commit. commands to manipulate the local git database which is the central view of the scm. Additionally, git can sync to a remote server (think github), and this is the repo server where many collaborators "check in" their codes for sharing.
Downloading open source sw
git clone https://github.com/singularityware/singularity.git	# download the whole sw repo
git tag								# see available tagged releases
git checkout tags/2.2						# switch to use the named tag release (2.2)


git against local copy of repository
git clone			# create a local copy of a source code tree
git commit -a 			# most basic workflow after edit, most like svn, commit all changes


git commit file1 file2		# check into local copy (but other don't see this change yet)
git commit file1 -m "comment"	# provide check in comment on cli rather than launch editor

git add file			# kinda feel like "add new file to be tracked"
				# but really is adding changes into the git db
git add -p 			# patch-based add (allow committing chunk of code at a time rather than whole file)

git status			# show commit staatus within the local copy of repo only.  
				# if the clone had been some time and master had seen other commits, 
				# it will NOT show up in the status command.  
				# only another git fetch would get these changes.


## think these are still acting on local copy.  in fact, it is likely that 
## git act on local copy, except for few commands to interact with master repo...

git log file1
git log 
git log --oneline         	# compact log, easier to read!
git log --oneline file		# changes pertaining to the specified file only
git log --oneline issue123	# changes pertaining to the specified branch only  (?)
git log --decorate
git log --graph			# 
git log --oneline --graph --decorate	# can alias to "lol" for this oft use combo
git log -p 			# patch: show diff introduced by each change (instead of just commit msg for the log)

git log issue123 ^master	# branch diff, changes in branch issue123 but NOT in master
				# ^ indicate "not in"

git show COMMIT_HASH		# details of the commit

git branch			# list branches.  * indicate the current branch working on.
git branch -r			# list all branches avail in (r)emote server
git branch issue123		# create a branch called "issue123" (eg after a bug#)
git branch --edit-description issue123	# modify a description for the named branch.  it brings up a text editor

git checkout -b issue123	# 
git checkout master		# swich to the master branch (master is trunk branch created by default)


git mergetool			# launch visual diff tool



git init 			# create a git repo based on content of the current dir (and sub dirs)


git remote add     repoName url	# set a repo name for current "git dir", and url in github where it would upload to
git remote set-url repoName url	# use this if need to change remote github/bitbucket url
				# url for the named repo need to be pre-created in github, bitbucket, etc

git push --set-upstream repoName master	# the first push to a new repo need to specify the repository and branch name 



git against central repository
git push			# get local copy pushed into "central", or source of clone.  other will get the changes now.
				# this uses the default, which really means git push origin master # for primary source, master branch.

git push origin master		# what "git push" is doing when other params are omitted
				# pushes my current "master" branch to central repo "origin" by uploading data (to github)

git pull			# sync local git db with the remote server db (eg github, aka central)
				# recommend to do this before pushing changes back to central.
				# pull (from central) daily or so when working on a branch to keep code merges manageable
				# and the pull does not "post" my local changes to central so no one knows about the local work 

git pull --rebase		# may want to do this before commit... so conflicts are local.
				# rebase has to do with where to insert changes into the original tree... 
				# rebase is typically the most desirable option
				# BUT...
				# in corp env, almost always better to use fetch and merge than pull --rebase
				# 


git fetch 			# get changes on master repo and sync them to local copy of the repo.  
				# conflict may arise from this.  
				# better resolve conflict here before committing/pushing.

git merge 			# merge branch


# it is prefered to resolve conflicts in local copy, 
# rather than push the changes out
# and have everyone look at changes at the global level, 
# which may cause lot of conflict in other's code.

# config git to use proxy
# note that shell env var http_proxy isn't heeded
git config --global http.proxy http://proxy01.eville.com:2011

git config --global --unset http.proxy


git config --global alias.proxy   "config --global http.proxy http://proxy01.eville.com:2011"
git config --global alias.noproxy "config --global --unset http.proxy"

git config --global alias.lol "log --oneline --graph --decorate"		# create alias "git lol"   # logd

git terminology

github
Example instructions to add files as git repo into github
git config user.email "tin6150@gmail.com"
git config user.name  "tin"

# can use git config --global  if no need to use diff settings per repository
git config --global credential.helper 'cache --timeout=3600'
git config --global github.user   tin6150
git config --global github.token  mytoken
git config --global color.ui      true

git remote add origin https://github.com/tin6150/psg.git
git push -u origin master

git in windows
Cygwin and MobaXterm has provided a quite usable unix-like bash environment for windoze. However, getting git to work has been very tricky :( The following info from stack overflow may help...
unset HOMEPATH
export HOME=/c # in MINGW64 from PortableGit bash terminal

in the git-bash terminal, git push will prompt for username in the cli, and a pop up GUI window for password.
git references

mercurial hg commands

hg clone https://bitbucket.org/galaxy/galaxy-dist/
hg update stable
	# setup and download the galaxy repo from bitbucket

Git the Princess

Thanks to the folks at toggl


Doc URL
https://tin6150.github.io/psg/sourceControl.html

(cc) Tin Ho. See main page for copyright info.


"ting"
"ting"