User Tools

Site Tools


software:git

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
software:git [2018/06/21 11:03]
dave
software:git [2018/09/24 14:19] (current)
dave
Line 7: Line 7:
 ===== How To Undo Stuff == ===== How To Undo Stuff ==
  
-==== How to revert ​a single file ==+==== Revert ​a single file ==
  
 <​code>​ <​code>​
Line 15: Line 15:
 And near the top of the output are instructions. And near the top of the output are instructions.
  
-==== How to revert ​changes made to local copy == +==== Revert ​changes made to local copy == 
 **Warning: ​ there is no confirmation prompt! ​ Don't type this unless you really mean bring your local copy back in sync with the current branch!** **Warning: ​ there is no confirmation prompt! ​ Don't type this unless you really mean bring your local copy back in sync with the current branch!**
 <​code>​ <​code>​
Line 21: Line 21:
 </​code>​ </​code>​
  
-==== How to unstage ​a staged file or directory == +==== Unstage ​a staged file or directory == 
 From [[https://​stackoverflow.com/​questions/​348170/​how-to-undo-git-add-before-commit|stackoverflow.]] From [[https://​stackoverflow.com/​questions/​348170/​how-to-undo-git-add-before-commit|stackoverflow.]]
  
Line 28: Line 28:
 </​code>​ </​code>​
  
-==== How to change ​a previous commit ==+==== Change ​a previous commit ==
  
 If you haven'​t pushed it yet, it is possible to make a new commit that is automatically merged with the previous commit. ​ Stage the changes you need to add to the previous commit with ''​git add''​ first, then: If you haven'​t pushed it yet, it is possible to make a new commit that is automatically merged with the previous commit. ​ Stage the changes you need to add to the previous commit with ''​git add''​ first, then:
Line 38: Line 38:
 This command will open ''​$EDITOR''​ for editing of the commit message and then merge the staged changes with the previous commit. ​ To avoid editing the commit message, include ''​--no-edit''​. This command will open ''​$EDITOR''​ for editing of the commit message and then merge the staged changes with the previous commit. ​ To avoid editing the commit message, include ''​--no-edit''​.
  
-==== How to undo the previous commit ==+==== Undo the previous commit ==
  
 <​code>​ <​code>​
Line 50: Line 50:
 ===== Other Useful Notes == ===== Other Useful Notes ==
  
-==== How to get a diff including all the changes between two revisions ==+==== Get a diff including all the changes between two revisions ==
  
 <​code>​ <​code>​
 git diff <​rev1>​^..<​rev2>​ git diff <​rev1>​^..<​rev2>​
 +</​code>​
 +
 +==== Merge Squash == 
 +
 +<​code>​
 +git merge --squash <​other_branch>​
 +</​code>​
 +
 +Applies all of the changes made to ''<​other_branch>''​ to the working copy as a single set of //staged// changes which is ready to be committed. ​ Use ''​git commit''​ as per usual.
 +
 +==== List Remote Branches ==
 +
 +After initially cloning a repository, git is only aware of the the default branch, which is usually ''​master''​.
 +
 +<​code>​
 +$git branch
 +* master
 +</​code>​
 +
 +Use ''​-a''​ to list remote branches:
 +
 +<​code>​
 +$git branch -a
 +* master
 +remotes/​origin/​HEAD -> origin/​master
 +remotes/​origin/​release
 +</​code>​
 +
 +===== Misc Tasks ==
 +
 +==== Show only the files that are modified as a commit ==
 +
 +This removes the diff lines from the ''​show''​ command (''​+''/''​-''​ lines):
 +
 +<​code>​
 +$git show <​hash>​ --name-only
 </​code>​ </​code>​
  
software/git.1529604198.txt.gz ยท Last modified: 2018/06/21 11:03 by dave