Git Cookbook: Difference between revisions

From Littledamien Wiki
Jump to navigation Jump to search
(Created page with "==Reverting file edits== <syntaxhighlight lang="bash"> $ git checkout HEAD [path] </syntaxhighlight> ==Syncing a repo with subsequent changes to the master== Scenario: Create...")
 
No edit summary
Line 1: Line 1:
==Reverting file edits==
=Staging files=
==Stage a file or files==
<syntaxhighlight lang="bash">
$ git add [path]
</syntaxhighlight>
 
==Stage all files==
What this won't do is stage deletes.
<syntaxhighlight lang="bash">
$ git add ./
</syntaxhighlight>
 
To stage everything including deleted files:
<syntaxhighlight lang="bash">
$ git add -A
</syntaxhighlight>
 
==Unstage a file or files==
This will unstage the file, but edits that have been made to the file will remain unchanged.
<syntaxhighlight lang="bash">
$ git reset [path]
</syntaxhighlight>
 
=Reverting file edits=
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
$ git checkout HEAD [path]
$ git checkout HEAD [path]
</syntaxhighlight>
</syntaxhighlight>


==Syncing a repo with subsequent changes to the master==
=Syncing a repo with subsequent changes to the master=
Scenario: Create a branch, make edits. In the meantime other work is being done by other members of the team. The time comics to push your changes out. The goal is to merge their changes into yours locally then push it all out.  
Scenario: Create a branch, make edits. In the meantime other work is being done by other members of the team. The time comics to push your changes out. The goal is to merge their changes into yours locally then push it all out.  


Line 31: Line 54:
</syntaxhighlight>
</syntaxhighlight>


==Commmiting changes==
=Commmiting changes=
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
$ git co myBranch
$ git co myBranch

Revision as of 21:25, 9 August 2012

Staging files

Stage a file or files

$ git add [path]

Stage all files

What this won't do is stage deletes.

$ git add ./

To stage everything including deleted files:

$ git add -A

Unstage a file or files

This will unstage the file, but edits that have been made to the file will remain unchanged.

$ git reset [path]

Reverting file edits

$ git checkout HEAD [path]

Syncing a repo with subsequent changes to the master

Scenario: Create a branch, make edits. In the meantime other work is being done by other members of the team. The time comics to push your changes out. The goal is to merge their changes into yours locally then push it all out.

  • See what files have been touched:
$ git status -s
  • View (unstaged) edits for a specific file:
$ git diff -- [path]
  • Switch from the local branch to 'master'.
$ git co master
  • Merge the updated local 'master' with the local branch, resolving any conflicts:
$ git branch
* master
  mybranch
$ git co mybranch
$ git merge master

Commmiting changes

$ git co myBranch
$ git status -s
  # add any files that need to be added to the commit
$ git commit -m 'commit message'
  # the "commit message" is required
$ git push origin myBranch

See the Mediabistro wiki for instructions on how to put the changes on 'preview'.