Let's assume we have a two branches (A
, B
), and we want to move the file test.xt
from branch A
to branch B
.
git checkout B
git checkout A -- test.txt
git status
git commit -m "Copy file test.txt"
git push
Let's assume we have a two branches (A
, B
), and we want to move the file test.xt
from branch A
to branch B
.
git checkout B
git checkout A -- test.txt
git status
git commit -m "Copy file test.txt"
git push
You can not delete the commit history from a branch, but you can create a new branch (without history because is new), push the files to the new branch and then delete the old branch.
The next example shows how to recreate the master branch.
# Create temporary branch
$ git checkout --orphan temp
# Add and commit all the files
$ git add -A
$ git commit -m "init"
# Delete current branch
$ git branch -D master
# Rename current branch to master
$ git branch -m master
# Push all the files to the new master branch
$ git push -f origin master
git rm --cached paper.txt
git add paper.txt
git commit -m "remove file paper.txt"
git push
git rm --cached -r .
git add .
git commit -m "remove all files from .gitignore"
git push