Skip to content

Instantly share code, notes, and snippets.

@yavuztas
Last active November 13, 2018 23:09
Show Gist options
  • Save yavuztas/c4d71d49430a57eeeb2336a09f68407a to your computer and use it in GitHub Desktop.
Save yavuztas/c4d71d49430a57eeeb2336a09f68407a to your computer and use it in GitHub Desktop.
Git commit individual files and revert workflow
#Get a list of files you want to commit
$ git status
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: file1
modified: file2
modified: file3
modified: file4
#Add the files to staging
$ git add file1 file2
#Check to see what you are committing
$ git status
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: file1
modified: file2
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: file3
modified: file4
#Commit the files with a commit message
$ git commit -m "Fixed files 1 and 2"
#If you accidentally commit the wrong files
$ git reset --soft HEAD~1
#If you want to unstage the files and start over
$ git reset
Unstaged changes after reset:
M file1
M file2
M file3
M file4
#For checking all branches
$ git pull --all
#List local branches and their remote tracking info
$ git branch -a
#Remove local branch
$ git branch -d <branch-name>
#Sycnronize remote tracking info from remote if you add "--dry-run" at the end it will just preview
$ git remote prune origin --dry-run
#Then if everything is fine you can run actual operation
$ git remote prune origin
#remove untracked files after git reset --hard
git clean -fd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment