Skip to content

Instantly share code, notes, and snippets.

@marcosdalte
Forked from sheremetat/gitflow.md
Last active July 1, 2021 21:05
Show Gist options
  • Save marcosdalte/112e15027806490f1d26889642f85e3e to your computer and use it in GitHub Desktop.
Save marcosdalte/112e15027806490f1d26889642f85e3e to your computer and use it in GitHub Desktop.
Git rebase workflow

Step 1: Checkout a new working branch from updated master

 git checkout -b <branchname>

Step 2: Make Changes

 git add
 git commit -m "description of changes"

Step 3: Sync with remote

 git checkout master
 git pull --rebase

Step 4: Update branch

 git checkout <branchname>
 git rebase master

 In case of conflicts: resolve conflict by looking at the files in question.
 git add <resolved files>
 git rebase --continue

Step 5: Squash your last N commits

 git rebase --interactive HEAD~N

Step 6: Push Changes

alternativelly create pull request and merge changes to master via UI

 git checkout master
 git merge <branchname>
 git push

Step 7: Delete working branch

 git branch -d <branchname>
 git push origin :<branchname>

Tips

How to show files changed in a git commit

 git show --name-only 8081fce782a733d1b23c38f7a3e5f11a2e0ebfdf

Verify first commit file

 git log --diff-filter=A -- xml/attributes/attributes.xml

Git rebase for alter date from commits

 git status
 git checkout -b teste
 git status
 git log

pegar commit anterior ao inicio do desenvolvimento

 git rebase -i 80da07e38e79494ee44b639f06c184fdd2e0ee55

nesse ponto alterar o pick por edit em todos os commits que vc quer alterar e salvar depois executar o comando abaixo e o continue até finalizar todos os commits

 GIT_COMMITTER_DATE="$(date)" git commit --amend --no-edit --date "$(date)"
 git rebase --continue
 GIT_COMMITTER_DATE="$(date)" git commit --amend --no-edit --date "$(date)"
 git rebase --continue

Stash

 git stash list

 // stash@{0}: nome da branch que foi realizado o `stash`: Descrição
 // stash@{1}: nome da branch que foi realizado o `stash`: Descrição

Show stash's files

 git stash show -p stash@{0}

Recover a file of stash

 git checkout stash@{0} \<nome do arquivo\>

How to pulled a remote branch

 git fetch origin branch_name

ou

 git fetch origin
 git checkout branch

ou

 git fetch http://github.com/user/repositorio.git name_branch
 git checkout -b name_branch FETCH_HEAD

How to show just your changes on git log

 git log --author="Marcos"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment